Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have an image gallery of sorts its displayed on the page using the following template code...

 <?php
        $featured = get_post_meta($post->ID,'_thumbnail_id',true);
        $attachments = get_children( 'post_type=attachment&orderby=menu_order&exclude='.$featured.'&post_mime_type=image&post_parent='.$post->ID ); ?>

       <ul id="fac">
       <?php foreach ($attachments as $attachment) {
             $img = wp_get_attachment_image_src($attachment->ID);
    $img_large = wp_get_attachment_image_src($attachment->ID, 'full'); ?>
       <li><a rel="example" href="<?php the_permalink() ?>"><img class="fac-img" src="<?php echo $img[0] ?>" width="<?php echo $img[1] ?>" height="<?php echo $img[2] ?>" /></a></li>
       <?php } ?>
        </ul>

The image linking to the main single page of the post.

Now is there any way that one there is only 1 image attached it doesn't show the link?

So you attach one image to the post it shows it on its own.

If however, you upload more than one image it adds the link around that image a long with link text 'click to view more images' or whatever.

Clicking that takes you to a new single.php page where all the images are there running a gallery js script which is already done.

Possible or not?

Thank you for any help.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

check how many posts were returned in your $attachments variable and output your desired markup for each case:

$featured = get_post_meta($post->ID,'_thumbnail_id',true);
$attachments = get_children( 'post_type=attachment&orderby=menu_order&exclude='.$featured.'&post_mime_type=image&post_parent='.$post->ID );

if( count( $attachments ) > 1 ):
    // more than 1 attachment
else:
    // just 1 (or 0)
endif;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.