• 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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);
    ?>

    Thread Starter baduist3

    (@baduist3)

    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 };?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Count posts in page (to determine legnth of text?)’ is closed to new replies.