Overriding Wordpress 1.5’s post number
One of the new features of Wordpress 1.5 that I don’t really like is the lack of control over how many posts appear on a page. You can set the max number of posts via the Options, Reading section in the admin panel.
Unfortunately, it sets a maximum posts-per-page value that applies across the entire site. This means that longer pages like category pages are trimmed down to the length of the front page, or the front page needs to be lengthened in order to accomodate the maximum number of pages on any other page throughout the site. It doesn’t make sense.
In an ideal world you’d be able to specify the maximum number of pages for category pages and the index page separately. Until that’s made an option in an official Wordpress release, here’s one way to offer special control for the number of posts that appear on the front page.
First, you need to have a home.php file in your themes directory. If you don’t, create it usingindex.php as a template.
In home.php, look for the loop, and add the following chunks of code immediately after the opening of The Loop:
< ?php
static $postnumber = 0;
if ($postnumber == "9") { break; }
else { ?>
Then, right before you close out the loop, add this piece of code:
< ?php $postnumber++; } ?>
If you know even a little bit about coding, you should be able to see that this creates a variable called $postnumber, then increments it during each iteration of The Loop until $postnumber equals a predefined amount (in this case, 9) at which point the loop ends.
You could change 9 to be however many posts you want to appear on your front page. What you choose to set in your Wordpress Admin panel will have no bearing on the front page.
Next step is to go to your Wordpress Admin panel, and change the show max posts to something high, like 25. That way, category pages won’t be cut off, and the front page won’t be ridiculously long.
0 Comments
No comments yet.
RSS feed for comments on this post.