WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] number of posts in one category (8 posts)

  1. 67thavenue
    Member
    Posted 5 years ago #

    What code can I use to display the number of posts in a given category, but not all categories.

    Thanks!

    -James

  2. MichaelH
    Member
    Posted 5 years ago #

    <?php
    //display post count for category 63
    $categories=get_categories('include=63');
    if ($categories) {
    foreach($categories as $category) {
    echo 'post count is ' . $category->count;
    }
    }
    ?>
  3. 67thavenue
    Member
    Posted 5 years ago #

    thanks!

    so, i replace "63" with my category name?

  4. MichaelH
    Member
    Posted 5 years ago #

    You would replace 63 with your category ID.

  5. MichaelH
    Member
    Posted 5 years ago #

    Or change this:

    $categories=get_categories('include=63');

    to

    $categories=get_categories('include='.get_cat_ID('your category name here'));
  6. 67thavenue
    Member
    Posted 5 years ago #

    Perfect! It worked!!!! Thanks again!

  7. wildhalf
    Member
    Posted 4 years ago #

    Micheal

    This works for what i am trying to do but how could i modify it to get the count for each of my categories...

  8. MichaelH
    Member
    Posted 4 years ago #

    Change this:
    $categories=get_categories('include=63');

    to

    $categories=get_categories();

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags