I recently had a client who requested his blog display posts similar to GigaOm.com — one featured excerpt, three featured headlines, followed by the standard Loop and pagination:

It’s a nice format that’s mostly easy to replicate, but I hit two small problems. First, the large blue “Featured” box was supposed to disappear once you begin paging (/page/2/), just like GigaOm. This required a conditional which said, “Show features if you’re on the homepage, but not on a paged page”:
<?php if ( is_home() and !is_paged() ) { ?>
<!--FEATURED STUFF-->
<?php } ?>
The second problem was that multiple query_posts on the same page disrupted the standard query, which also caused pagination to fail. In the end, what fixed it was an explanation I found in the WP support forum archives, written by the always-knowledgeable Kafkaesqui:
To get proper pagination with query_posts() we need to recreate it through the ‘paged’ parameter or query. Best way to do this is to ask WordPress for the “page” we happen to be on, and use that as our ‘paged’ value.
He suggested combining query_posts with this bit of code:
<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
?>
Add it all together and you get a working index.php template that functions like GigaOm:
<?php get_header(); ?>
<div id="content">
<?php if ( is_home() and !is_paged() ) { ?>
<!--FEATURED EXCERPT-->
<div id="feature">
<?php query_posts('category_name=featured&showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a></h2>
<p class="postmetadata">
Posted by <?php the_author_posts_link(); ?>
on <?php the_time('F jS, Y') ?>
<span class="commentcount">
<?php comments_popup_link('No Comments', '(1) Comment', '(%) Comments'); ?>
</span></p>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<!--FEATURED HEADLINES-->
<?php query_posts('offset=1&category_name=featured&showposts=3'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a>
<span class="commentcount"><?php comments_popup_link('No Comments', '(1) Comment', '(%) Comments'); ?>
</span>
</li>
<?php endwhile; ?>
</ul>
</div>
<!--END FEATURED-->
<?php } ?>
<!--STANDARD LOOP-->
<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=-5&showposts=3&paged=$page");
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></h2>
<p class="postmetadata">
Posted by <?php the_author_posts_link(); ?> on <?php the_time('F jS, Y') ?>
<span class="commentcount">
<?php comments_popup_link('No Comments', '(1) Comment', '(%) Comments'); ?>
</span></p>
<div class="entry">
<?php the_content('» Read More'); ?>
</div>
</div>
<?php endwhile; ?>
<!--PAGINATION-->
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Note: a “cat=-5 (or whatever)” parameter was added to the second query so that Featured posts would not display redundantly within the Loop.
Follow me on Twitter
11:55 pm
I didn’t know this before and would continue missing the flaw had you didn’t write this post. Thanks a lot! Someone needs to compile a best practice article when using query_posts().
12:18 am
Glad you found it useful! I had Googled for the “get_query_var” solution before, but until this week had only found vague results. It’s definitely not something I would’ve otherwise written myself.
12:31 pm
Don’t you have to rewind_post() or save the query first. I have not tried this approach yet, but I remember on WP loop discussion that the query has to be rewinded. Your code seems to pass through the loop only once.
1:05 pm
Once again, big props for thinking a bit outside the box and sharing it in straightforward English. Something like this was actually on a to-do list for a project I’m working on, and it works like a charm…so far.
I did replace this: &category_name=featured with this: &cat=6 to mimic Mimbo’s structure, and it worked the same. Any reason that might cause an error somewhere else?
4:27 am
I have tried the steps above, and there are no errors displayed. Unfortunately, the featured posts are not displaying at all. The container divs are displaying, but without any content. I did include the category ‘featured’.
And another suggestion – if you can spend a moment, can you please make the queries using a tag like ‘features’? That is better than increasing the number of categories.
Thanks in advance.
7:56 pm
I’m new to coding and I need some help:
On my blog, http://www.ResponsibleChina.com, I have a “Latest Post,” followed by a “Featured Post,” and then “Asides.” After “Asides,” I’d really like to display some more recent posts, excluding the first one at the top of the page.
How do I do that?
11:24 am
Exactly what I need Darren! Been searching for this functionality for a long time now. Thanks a lot!
12:16 pm
hi,
i really liked the way you design the blog , post… just AWEsome :)
thanks for the post . what is that sidebar…. how did you do that and did you design this theme…. wow!
thankyou for the codes
ravi :)
12:41 am
Thanks for this post..!
I got stuck on this issue and was looking for the help since a few days..
Also liked the way you designed your blog,
nice work…! keep it up..
10:14 am
thanks for this great info
6:20 am
Seriously, this is one of the best posts about query_posts and the loop! Saved me a lot of time, thank you.
1:17 pm
Thanks for this post! It helped me out a lot!
10:27 am
Very chyic
—-
signature: http://renaiaaancec.livejournal.com :D