• Is there a way to echo the number of image attachments attached to a post. I am using the image.php function to display a gallery of images attached to a post that shows one image at a time. I’d like to be able to display “Image 3 of 10” somewhere on the page so readers will know how many pictures are in the gallery. Is there any way to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • What about using

    $args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image'
    }
    $images =& get_children( $args );
    %count = count ($images);?>
    Thread Starter mattloak

    (@mattloak)

    Thanks. My php is a little rusty so I couldn’t get this to work. There appeared to be some errors in that code too. I cleaned it up as best I could and tried this:

    <?php echo $args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image'
    )
    $images = get_children ($args);
    $count = count ($images); ?>

    But I’m getting and error that says:

    Parse error: syntax error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’

    on this line: $images = get_children ($args);

    Any help fixing this would be appreciated.

    Thread Starter mattloak

    (@mattloak)

    oh, and I tried it without the echo too and got the same error.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Counting Image Attachements’ is closed to new replies.