Do you realize that my WordPress blog displays 3 entries on the front page and 10 entries in archives and categories?
By default, WordPress displays a same number of entries on the front page and this setting also applies to archives and categories.
Here is how I do it;
Open your index.php file, found in your theme folder ( /wp-content/themes/themes_name/ ) folder and look for lines 5 and 7.
They should appear something like this:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
Replace those lines with this code:
<?php $custom_loopcount = 0; ?>
<?php if (have_posts()) : while ((have_posts()) && ($custom_loopcount < 3)) : the_post(); ?>
<?php if (is_home()) $custom_loopcount++; ?>
What we’re doing here is changing WordPress Loop by telling the script that when viewing the Front page, show 3 posts. ( You can see on second line there is number 3 )
However, when viewing archives or categories, WordPress Loop will follow normal loop setting.
Normal settings can be change at your admin pages,
Option –> Reading
Then, change Reading Option –> Blog Pages to show at most 10 posts.
However, if you’re using old WordPress Theme format ( version 1.5.x ), you have to change it to latest WordPress themes format first.
This is how I change it,
Old Format;
<?php if ($posts) {
foreach($posts as $post)
{
start_wp();
?>
<div class=”post”>
Your Post
</div>
<?php else : ?>
<?php endif; ?>
New format ;
* Change it like this!
<?php $custom_loopcount = 0; ?>
<?php if (have_posts()) : while ((have_posts()) && ($custom_loopcount < 3)) : the_post(); ?>
<?php if (is_home()) $custom_loopcount++; ?>
<div class=”post”>
Your Post
</div>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
Great post – I used this on my site. You explain the post limiting very completely.
Thanks.