Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何从帖子中获取所有附件[视频、图像]并在UL in模板中显示_Wordpress - Fatal编程技术网

Wordpress 如何从帖子中获取所有附件[视频、图像]并在UL in模板中显示

Wordpress 如何从帖子中获取所有附件[视频、图像]并在UL in模板中显示,wordpress,Wordpress,我编写了一些代码,可以在UL中显示所有附件图像,以便在自定义帖子类型上进行侧滚。客户端现在也希望返回视频。现在,我正在使用正则表达式解析帖子中的所有图像,但它并没有抓取视频。另外,我讨厌依赖正则表达式,因为目前的实现不可能同时抓取url等 是否有办法获取与帖子相关联的所有附件(不包括自定义字段缩略图),然后将附件填充到页面上的某个元素中 这将调用所有附件类型-只需为其他mime类型(png、gif等)添加额外语句即可 <?php $thumb_ID = get_post_thu

我编写了一些代码,可以在UL中显示所有附件图像,以便在自定义帖子类型上进行侧滚。客户端现在也希望返回视频。现在,我正在使用正则表达式解析帖子中的所有图像,但它并没有抓取视频。另外,我讨厌依赖正则表达式,因为目前的实现不可能同时抓取url等


是否有办法获取与帖子相关联的所有附件(不包括自定义字段缩略图),然后将附件填充到页面上的某个元素中

这将调用所有附件类型-只需为其他mime类型(png、gif等)添加额外语句即可


    <?php 
$thumb_ID = get_post_thumbnail_id( $post->ID );
$attachments = get_posts(array(
        'post_parent' => $post->ID,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby'        => 'title',
        'order'           => 'ASC',
        'exclude' => $thumb_ID,
    ));

if ( $attachments ) {   
foreach( $attachments as $attachment ) {
    $attachment_mime = wp_check_filetype(wp_get_attachment_url($attachment->ID) );
            $title = apply_filters( 'the_title' , $attachment->post_title );
            if ( $attachment_mime['type'] == 'image/jpeg') {echo '<li><img src="' . wp_get_attachment_url( $attachment->ID ) . '" alt="'.$title.'"  /></li>'; }
            elseif( $attachment_mime['type'] == 'video/mp4'){echo '<li><video class="video-js vjs-default-skin" controls data-setup="{}"><source src="'.wp_get_attachment_url( $attachment->ID ).'" type="video/mp4" /></video></li>';}           
}
}?>