The most common home page on WP powered site contains posts listed in chronological order (from the newest to the oldest one). But sometimes we need different layout. Fortunately WP is quite flexible and allows to create many customized lists of posts.
I’m not going to list all of them since I guess such list would never end up. But I will show some of the most popular customizations including required changes.
All changes will be applied to index.php file (the one within folder with theme we use) since that’s the one responsible for main page look.
I have already written about two custom main pages:

But they use different functions.
Here I would like to show how functions like <?php $posts=query_posts($query_string . ' '); ?>, <?php query_posts(" "); ?> and <?php $temp_query = $wp_query; query_posts(' '); ?> can be used.
The best one (in my opinion ;) ) is the first one. It has one important advantage over the other two. If we set to display 10 posts per page(in admin panel -> option -> reading) and we have more then 10 posts meeting the condition we set in our index.php file functions <?php query_posts(" "); ?>and <?php $temp_query = $wp_query; query_posts(' '); ?> WON’T work properly. On following pages we will see the same posts as on the main page.. That’s why I would recommend them only in situations when number of posts we want to display on main page is smaller then number of posts per page set in admin panel.

The most common usage (in my practice):
1. <?php $posts=query_posts($query_string . ' '); ?>
In index.php file we need to replace <?php if (have_posts()) : while (have_posts()) : the_post(); ?> with below piece of code to have:

  • posts listed in reverse chronological order (from the oldest to the newest one)
    <?php $posts=query_posts($query_string . '&order=asc');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts ordered alphabetically
    <?php $posts=query_posts($query_string . '&orderby=title&order=asc');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts from categories *extras* and *images* only
    <?php $posts=query_posts($query_string . '&category_name=extras,images');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts from category *extras* published in *October*
    <?php $posts=query_posts($query_string . '&category_name=extras&monthnum=10'); if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts by user *Neo*
    <?php $posts=query_posts($query_string . '&author_name=neo');
    if (have_posts()) : while (have_posts()) : the_post(); ?>

2. <?php query_posts(" "); ?>
In index.php file we need to replace <?php if (have_posts()) : while (have_posts()) : the_post(); ?> with below piece of code to have:

  • posts published on particular day of the month (for example if we always publish reports on the 25th of the month )
    <?php query_posts("day=25"); if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts tagged with tag *scripts*
    <?php query_posts("tag=scripts"); if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts containing one of listed tags
    <?php query_posts("tag=bread+baking+recipe"); if (have_posts()) : while (have_posts()) : the_post(); ?>
  • posts from category *extras* published in June (for example)
    <?php query_posts("category_name=extras&monthnum=6"); if (have_posts()) : while (have_posts()) : the_post(); ?>

Of course we can mix parameters to achieve required result. We can set to display for example posts written by Neo which belong to category *extras* an so on..

3. function <?php $temp_query = $wp_query; query_posts(' '); ?> need to be inserted BEFORE <?php if (have_posts()) : while (have_posts()) : the_post(); ?> (in idex.php file) and requires inserting <?php $wp_query = $temp_query; ?> right after <?php endif; ?>. That reason (in addition to limited usability I’ve mentioned at the beginning) makes it not really useful ;). Hence I won’t show you any example since function <?php query_posts(" "); ?> will be just enough.

NOTE! Very often it is said that instead of category_name=extras we can use cat=5 (where 5 is an ID number of category extras) but.. many times I had problems to make it working hence I prefer to use parameter category_name.