• Anybody know how i can display the amount of posts in a category on a page. I want to create an image map on a picture with the link being the amount of posts in that category.

    SO how can i display the category count??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Use get_categories–in this case for category 3

    <?php
    $args=array(
      'include' => 3,
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $categories=get_categories($args);
      foreach($categories as $category) {
        echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . ' with '  . $category->count . ' posts </a> </p> ';
      }
    ?>

    See Function_Reference/get_categories for more arguments

    Thread Starter wildhalf

    (@wildhalf)

    can i use the category name instead of the id

    $catid = get_cat_ID('your category name here');
    $args=array(
      'include' => $catid,
      'orderby' => 'name',
      'order' => 'ASC'
      );
    Thread Starter wildhalf

    (@wildhalf)

    Michael

    Thanks for all your help. I have one more question when the category count is 0 there is nothing printed. Is there any way i can print out the categories with 0 posts also

    That link above would have told you about hide_empty

    $args=array(
      'hide_empty' => 0,
      'include' => $catid,
      'orderby' => 'name',
      'order' => 'ASC'
      );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Category Post Count’ is closed to new replies.