无法获取自定义帖子类型的图库图像URL

时间:2019-12-08 23:57:35

标签: wordpress-theming custom-post-type

我有一个名为books的CPT,我可以像这样遍历它

<?php
$loop = new WP_Query(array(
    'post_type' => 'books',
    'tax_query' => array(
        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => 'romance'
        )
    )
)
);
while ($loop->have_posts()):
    $loop->the_post();

endwhile;
wp_reset_query();

?>

现在我想用自己的班级显示Post Galley图片,所以我尝试使用此代码

   if ( $gallery = get_post_gallery( get_the_ID(), false )){
       foreach ( $gallery['src'] AS $src ) {
           ?> 
            <img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
            <?php
        }
   }

来自Here at codex

喜欢

<?php
$loop = new WP_Query(array(
    'post_type' => 'photo',
    'tax_query' => array(
        array(
            'taxonomy' => 'phototypes',
            'field' => 'slug',
            'terms' => 'public'
        )
    )
)
);
while ($loop->have_posts()):
    $loop->the_post();
    if ($gallery = get_post_gallery(get_the_ID() , false))
    {
        foreach ($gallery['src'] AS $src)
        {
?> 
                    <img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
            <?php
        }
    }
endwhile;
wp_reset_query();
?>

但这不会返回任何内容,甚至不会返回空的图像标签,也不会出现错误。你能让我知道我在这里想念什么吗?

0 个答案:

没有答案