Forums

Post attachment count? (8 posts)

  1. Vast HTML
    Member
    Posted 2 years ago #

    Is there a way to post how many attachments a post has?

  2. Vast HTML
    Member
    Posted 2 years ago #

    ?

  3. Justin Tadlock
    Member
    Posted 2 years ago #

    This might work:

    $attachments = get_children( array( 'post_parent' => 100 ) );
    $count = count( $attachments );
  4. Vast HTML
    Member
    Posted 2 years ago #

    im gussing the 100 is the post id?

  5. fredhead
    Member
    Posted 2 years ago #

    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.

  6. aurelie@bear-to-bear.net
    Member
    Posted 2 years ago #

    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.

  7. aurelie@bear-to-bear.net
    Member
    Posted 2 years ago #

    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 ! ;)

  8. mattloak
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.