• hello everyone,
    i am new to wordpress and dont know much about coding.

    i just want to know that how i can show the total no post that a category have, i.e. if a category “dogs” has total 30 posts in it. Then how i can show it on a page like DOGS(30 posts), CAT(20 posts).

    My basic need is to show total no. of posts that a category have.

    Thanks to everyone in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Welcome to WordPress!

    1. We set # of posts per page for site wide in Dashboard > Setting > Reading > “Blog pages show at most” (and most themes which respect this setting will use this setting)

    2. For custom posts per page, you need to put custom code filter in pre_get_posts hook

    e.g. Add following code to your functions.php of your theme and see if dogs category page posts are changed?

    // Change posts per page in the dogs category
    add_action( 'pre_get_posts', 'wm_dogs_category_per_page' );
    function wm_dogs_category_per_page( $query ) {
    	if( $query->is_main_query() && is_category( 'dogs' ) && ! is_admin() ) {
    		$query->set( 'posts_per_page', '30' );
    	}
    }

    This code should work.

    //Get the category based on the id and return the count.
    $category = get_category($id);
    $count = $category->category_count;

    Good luck with your project.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘No. of post in a particular category’ is closed to new replies.