Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Vast HTML

    (@erichamby)

    ?

    This might work:

    $attachments = get_children( array( 'post_parent' => 100 ) );
    $count = count( $attachments );
    Thread Starter Vast HTML

    (@erichamby)

    im gussing the 100 is the post id?

    This helped, Greenshady, thanks!

    Also, within the loop, my code looked like:

    $attachments = get_children( array( ‘post_parent’ => $post->ID ) );

    If that helps anyone else.

    aureliebear-to-bearnet

    (@aureliebear-to-bearnet)

    Hello everybody,

    Is there somebody who managed to count the number of attachment files (images) in a post ? Is there a function in WordPress which allow to display it (something like “wp_get_attachment_number();”) ?
    I would like to display this variable in the file “single.php”…

    Thx for your help ! ??

    BR,
    Aurélie D.

    aureliebear-to-bearnet

    (@aureliebear-to-bearnet)

    Ok, my problem is resolved ! ??
    Here is the code I added on my file “single.php” :

    <?php
    $attachments = get_children(array('post_parent'=>$post->ID));
    $nbImg = count($attachments);
    echo 'There are '.$nbImg.' pictures on this post.';
    ?>

    Thx for your ideas ! ??

    How could you use that code to display on the attachement page and show ho many attachments are attached to the parent? What I’m trying to accomplish is to display “Image #3 of 5” when viewing the single attachment through the image.php template.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Post attachment count?’ is closed to new replies.