How to display different number of entries in Wordpress front page and archives
May 21st 2007azmanTips & Tricks
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; ?>
Similar Posts
- How to use built-in Smileys and Emoticons in Wordpress
- It’s really work – How to Resolve Wordpress Fatal Error: Allowed memory size of xxxxx bytes exhausted (tried to allocate xxxxx bytes)
- How to transfer domain, server and your Wordpress blog – Diyanazman’s way!!
- Prepare Yourself for the Unthinkable
- The new masthead
1 Comment »



Joe on 03 Jul 2007 at 9:47 am #
Great post – I used this on my site. You explain the post limiting very completely.
Thanks.