Combining Featured Posts with the Standard Loop
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.
Popularity: 2% [?]
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().
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.
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.
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?
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.
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?