Justin Blanton shows how to limit the number of posts that are displayed on the index page of your WordPress 1.5 blog. You can set the Show At Most option but that is for all pages including archives.
Limit Number Of Posts With WordPress
One of the first things I noticed when I started to setup WordPress was that there was no way to control the number of posts displayed on the index page from the admin panel. Yes, there is the “Show at most” option, but this is a site-wide variable and works to treat all of your pages the same.
To limit the number of posts on your index page while allowing all other pages to look to the “Show at most” setting, check out Justin’s hack.
Do you like this article? Submit it to Blogosphere News!
5 Responses
mmedia
February 27th, 2005 at 4:52 am
1Hi, do you know what code must we insert inside “else { ?>”. I’m tried it, but int gives me many “parsers unexpected ‘{’ or ‘<’ errors”.
Sorry by this question, but Justin doesn’t allow comments in his blog.
Thanks
John
February 27th, 2005 at 9:36 am
2You need to add the first snippet of code at the beginning of your loop right after
<?php while (have_posts()) : the_post(); ?>
then add <?php $ctr++; } ?> right before the <?php endwhile; ?>
That should do it for you. Also, be sure to change the X to the number of posts you want displayed on the index.php page.
mmedia
February 27th, 2005 at 1:43 pm
3Thanks for your answer, John, but I have this in the code:
“< ?php static $ctr = 0;
if ($ctr == "1") { break; }
else {
} ?>
and I have this message:
“Parse error: parse error, unexpected ‘< ' in /home/proyecto/public_html/sol/wp-content/themes/sol/index.php on line 60"
line 60 is "”
Thanks.
John
February 27th, 2005 at 1:58 pm
4I would need to see all of the code because many times the line number given in the error is not the correct line. Sometimes it’s the line before.
But it appears you just have an extra <\ somewhere.
Also, you can’t just post the code in a WordPress comment box because WordPress will trash it. Send the index file to me via email. john at johnhesch dot com.
Dusky
February 27th, 2005 at 4:11 pm
5There’s a plug-in available that does the same, and a bit more. Save it to your computer, configure it to match your needs, upload it, and activate it.
http://rephrase.net/miscellany/05/perpage.phps