• I have set my wordpress to display 12 posts on home page. Now I am trying to limit the posts to 5 pages in category.php. How can I set it to display 5 posts per page for category.php. Below is the code that is used for index.php

    while (have_posts()) : the_post();

Viewing 5 replies - 1 through 5 (of 5 total)
  • goto ADMIN->SETTINGS->READING and change the 12 to 5.

    Add up the following code in your functions.php file. Make sure that you have a copy of the file on your computer or somewhere before attempting to edit the file.

    function limit_posts_per_archive_page() {
    	if ( is_category() )
    		set_query_var('posts_per_archive_page', 2); // or use variable key: posts_per_page
    }
    
    add_filter('pre_get_posts', 'limit_posts_per_archive_page');

    In the above code the post limit is set to 2. You can change it from the above code as shown below.

    set_query_var('posts_per_archive_page', enter the number of post limit here);

    Thanks

    Thread Starter illusime

    (@illusime)

    Thanks Thejas Kamath. That’s what I am looking for.

    Thread Starter illusime

    (@illusime)

    Let’s say I want category “abstract” to limit to 2. How do I do it? I tried using “if(in_category( ‘Abstract’ ))”

    But it doesn’t work.

    yes. in_category(‘abstract’)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Limit Posts on Category Page’ is closed to new replies.