CountPost WordPress Custom Taxonomy

What's the easiest way to add "count posts" to the category listing as seen as below?

?php
if($categories){
    foreach($categories as $category) {
        $output .= 'lia href="'.get_category_link( $category-term_id ) . '" title="' . esc_attr( sprintf( esc_html__( 'View all posts in %s','themename' ), $category-name ) ) . '"' . $category-name . '/a/li' . $separator;
    }
    echo trim($output, $separator);
}

Topic listing count Wordpress

Category Web


I do not know exactly what you mean, but I think you need something like this?

$categories = get_terms( array( 'taxonomy' => 'category' ) );
if ( $categories ) { 
   $output = '';
   foreach( $categories as $category ) {
      $output .= '<li title="' . __( 'View all', 'themename' ) . ' ' . $category->count . ' ' . __( 'posts in', 'themename' ) . ' ' . $category->name . '">' . $category->name . ' ' . $separator . '</li>';
   }
   echo trim( $output, $separator );
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.