如何做'不打印缩略图图像,如果它只有一个?WORDPRESS


How to don't print thumbnail image if it is only one? WORDPRESS

我在我的single.php中使用代码:

<?php echo show_all_thumbs(); ?> 

打印我所有的帖子缩略图。

如果它只是一个缩略图,如何不打印它?如何做检查:如果只有一个图像,什么都不做…?

我显然也

:

function show_all_thumbs() {
    global $post;
    $post = get_post($post);
    /* image code */
    $images = &get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->ID); 
    if ($images) {
        foreach ($images as $imageID => $imagePost) {
            unset($the_b_img);
            $src = wp_get_attachment_image_src($imageID, false);
            $the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
            $thumblist .= '<a class="gallery_colorbox cboxElement" href="'. $src[0] .'">'.$the_b_img.'</a>';
         }
    }
    return $thumblist;
}

您可以使用count函数查看图像数量:replace

if ($images) {

if (count($images) > 1) {
相关文章: