Forums

Count posts in page (to determine legnth of text?) (3 posts)

  1. baduist3
    Member
    Posted 4 years ago #

    Hi.
    i have a lots of categories in my blog, and some of them have a lots of posts, while others have only a few.

    What i want to do is display a tower of google adwords on the sidebar of the category page, if there are more than X posts.

    so, i was thinking of making a php IF condition to check the number of posts whoing on the current page.

    I would appreciate any help doing this.

    Thanks.

  2. MichaelH
    Volunteer
    Posted 4 years ago #

    Well if you are using The_Loop to display posts then assuming your posts are in an array called $posts, you could use the the count statement:
    <?php
    echo 'count of posts is ' . count($posts);
    ?>

  3. baduist3
    Member
    Posted 4 years ago #

    Thanks, this is exactly what i was looking for.

    This is how i used it, if anyone needs this:

    <?php
    $howmany = count($posts);
    if ($howmany >= 5) { ?>
    Some HTML code here...
    <?php };?>

Topic Closed

This topic has been closed to new replies.

About this Topic