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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s