• I need to display on the category page something like this:

    Quote: [number of quote posts published in the category] | Status: [number of status posts published in the category]

    How do I do that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • To display total post published you can put this in your template (archive.php / title_header.php):

    <?php echo term_count() . 'post published' ?>

    But.. I’m not quite understand with ‘Quote’ and ‘Status’ that you mean.
    I think you need tell us your website link.

    • This reply was modified 8 years, 2 months ago by MonkimoE.
    • This reply was modified 8 years, 2 months ago by MonkimoE.
    Moderator bcworkz

    (@bcworkz)

    MonkimoE, I think the OP is referring to the post format type that themes often implement. Twentysixteen for example, has these formats and many more available. term_count() sounds like a useful function, but I don’t think it’s part of WP core. Could it be something from a theme or plugin you use? If you had wp_count_terms() in mind, this counts the number of different terms, not how many times any one term is used.

    ewlarme, the post format of each post is managed by the post_format taxonomy. The format is just another taxonomy term like categories and tags. You could do a count query for each format you’re interested in. It’s a little easier to code if you use get_posts() with a tax_query argument for both the current category and the post_format you’re interested in. Then use count() on the returned array.

    Hi,

    Sorry.. I was wrong. My 1st answer is to display total post in custom taxonomy.

    To display total post in regular category:

           <?php
            $args = array(
      		'post_type'    => 'post', //or change to your custom post_type
      		'post_status'  => 'publish',
    	);
    	$the_query = new WP_Query( $args );
    	echo $the_query->found_posts . 'post published' ;
            ?>
    

    put in your template (archive.php / title_header.php)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display the number of posts of each post type on the category page?’ is closed to new replies.