Under Reading Settings, I can specify how many blog posts to display on a page. However, I would like to customize this a bit. For example, I want to only display 2 posts on the “/” page, but 3 posts on “/page/2”, “/page/3”, etc. Any way to customize the homepage to display one less post than the other pages?
Leave a Reply
You must be logged in to post a comment.
There is no option to change the number of posts per page, archive, tag or category from the admin but you can use query_posts()
posts_per_page
to set the number.for example in your theme’s index.php file or if you are using a static page as your home_page the page.php file add this snippet of code above the loop
what it does is check to see if you are on the home page or front page and if you are then it changes the number of posts to show.
another example is to show different number of posts for different categories:
here we use the conditional tag is_category() to check which category we are in based on that we set the number of posts to display.
For cats we set 7, for dogs we set 4 and if its just random category we display 10.
http://coffee2code.com/wp-plugins/custom-post-limits/
By default, WordPress provides a single configuration option to control how many posts should be listed on your blog. This value applies for the front page listing, archive listings, category listings, tag listings, and search results. Custom Post Limits allows you to override that value for each of those different sections.
Specifically, this plugin allows you to define limits for:
I found this thread although my requirements were a bit different from the OP’s. I needed to have 16 posts on the first page and subsequently 15 posts on the next pages. I got to this solution thanks to @Jan Fabry’s thread ‘How to show a single post on the front page but have normal paging‘.
I’m posting the solution here since it seems appropriate to the title of the thread and also while Bainternet’s solution works, the WP codex discourages using the query_posts() function. Furthermore, there will be a duplicate post on page 2 since we didn’t offset the subsequent posts (WordPress thinks there are only 15 posts on the frontpage even though there are 16)
The offset is calculated from page 2 onwards. So if you are on page 2 and the posts per page in the dashboard settings is 15, the offset is ((2-2) * 15) + 16 = 16 on page 3 it is 31.
There’s also and extra check that the query is the main query as outlined in the codex in the pre_get_posts hook.