Post limit per page for different pages

Put this code in your function.php file in your template foldier.

function limit_posts_per_page() {
if ( is_category(5) )
return 1;
else
return 5; // default: 5 posts per page
}

add_filter(‘pre_option_posts_per_page’, ‘limit_posts_per_page’);

function limit_posts_per_archive_page() {
if ( is_category(5) )
set_query_var(‘posts_per_archive_page’, 1); // or use variable key: posts_per_page
else
set_query_var(‘posts_per_archive_page’, 5); // or use variable key: posts_per_page
}

add_filter(‘pre_get_posts’, ‘limit_posts_per_archive_page’);

I have one category (category id=5) that I want to have a limit 1 post per page and every other categories to have 5 posts per page.

That is.

Advertisements