• Ok. I’ve reached the limit of my ability. I’ve searched the Codex, the Forum, and my navel and I can’t figure this one out.

    I want to show the number of posts in a category when I’m on the archive page for the category.

    For instance, when I click on the “Cat1” link and go to the archive for Cat1, I want a headline that says “21 Posts in Cat1.” I managed to do this for the Author archive, but I can’t seem to find the right combinations of template tags to do it for the Category.

    I *don’t* want to show the totals in the sidebar, only in the headline to the Archive page.

    Any clues?

    Please?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hmm, not exactly sure how to get it to say in the headline unless you’re having it output as headlines, but this is the code I use to show number of posts in a category on my archives page.

    <?php wp_list_cats(‘sort_column=name&optioncount=1’); ?>

    A little more than a tag combo, but it works:

    <?php if(is_category()) : ?>
    <?php echo count($wpdb->get_col("SELECT rel_id FROM $wpdb->post2cat WHERE category_id = $cat;")); ?> posts in <?php echo get_the_category_by_ID($cat); ?>
    <?php endif; ?>

    You can leave off the if(is_category()) test (and endif) if this is being added to a category.php template.

    Thread Starter logista

    (@logista)

    @lawtai: I tried every incarnation of wp_list_cats, but couldn’t get it to give the result for only the Category I was in.

    @kafkaesqui: Works a treat! Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show # of posts on Category Archive page?’ is closed to new replies.