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

I use code in my single.php:

<?php echo show_all_thumbs(); ?> 

to print all my post thumbnail image.

Read More

How to don’t print it if it is only one thumbnail image? How to do check: if it is only one image, do nothing…?

My functions.php:

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

Related posts

1 comment

  1. You can check the number of images with the count function: replace

    if ($images) {
    

    with

    if (count($images) > 1) {
    

Comments are closed.