Special Home Page
The Home page of your site is the entryway for many visitors. By default, WordPress shows nothing but your most recent posts. Alternatively, WordPress makes it easy to set a page as your Home. I find that neither of these are sufficient and take another approach. If your templates contain a file named home.php then that template file will be used instead of the default WordPress options.
Create home.php
Simply copy your index.php to home.php. Most of the template will be the same except for a few minor modifications.
Sticky Posts
Sticky posts are those that will remain at the top of your home page regardless of their age. Create a hidden category named ‘_sticky’ and make note of it’s ID. Edit your home.php. Shortly after the <div id="content"> tag enter code similar to the following:
<?php query_posts('cat=86&showposts=2');?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class='post' id='post-<?php the_ID(); ?>'>
<h2 class='articleHeadline'>
<?php the_title(); ?>
</h2>
<p class='article'>
<?php the_content('Read the rest of this entry'); ?>
</p>
</div>
<?php endwhile; ?>
<?php endif; ?>
Firstly, make certain you replace 86 with the ID of your _sticky category. Now, some explanation of what is happening. The block which starts at <?php if (have_posts()) : ?> and ends at <?php endif; ?> is the standard WordPress Loop. So the trick here lies within <?php query_posts('cat=86&showposts=2');?>. This function call requests the most recent 2 (showpost=2) posts in the category with an ID of 86 (cat=86).
Display Regular Posts
Now in order for regular posts to display, we must reset our posts query. Let’s do a little more than that by also excluding all categories we wish to remain hidden. Just before the next Loop, add the following:
<?php query_posts('cat=-1,-86&showposts=10');?>
Here we are excluding categories with the IDs of 1 and 86 and then displaying the most recent 10 posts.
This article introduced two key concepts, the function query_posts and the Loop. Do a little digging into these concepts and you have gained large amounts of control over your site’s display.
Reference links:






