最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Not Able to Get Custom Post Type Gallery Images URL

programmeradmin4浏览0评论

I have a CPT called books and I am able to loop through it like

<?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();

?>

Now I want to display the Post Galley images with my own class so I tries to use this code

   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
        }
   }

from Here at codex

like

<?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();
?>

But this is not returning anything , not even empty image tags and no error. Can you please let me know what I am missing here?

发布评论

评论列表(0)

  1. 暂无评论