Reputation: 39
My wordpress
shows recent posts on the home page. Settings are 18 posts per page. How can I make some rule to show 18 posts on the first page (as configured) and 8 posts on the second and following pages?
<?php while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; ?>
Have tried the following:
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ($query->is_main_query()){
if (is_home()){
$query->set('showposts', 18);
}
else {
$query->set('showposts',7);
$query->set('posts_per_page',7);
}
}
return $query;
}
No effect :-(
Upvotes: 0
Views: 490
Reputation:
You can use the function is_home() to check where you are : http://codex.wordpress.org/Function_Reference/is_home
In your php function if your not in home you can change the post number per page, but it could make some issues on your navigation function.
Have you tried this plugin? http://wordpress.org/extend/plugins/custom-posts-per-page/
It could contains some interesting code to resolve your problem.
Upvotes: 2