Issue #1
Do not use query_posts()
to create secondary loops; it is intended only for modifying the Primary Loop. To create a secondary loop, use WP_Query()
or get_posts()
:
It is always best practice to keep your secondary/custom loops separate from the main query, unless your goal is to modify the primary loop.
(If you need further direction, let me know and I'll add code examples. I can't see your pastebin content at the moment.)
Edit
I see several issues:
You've got your main loop inside your secondary loop:
<?php while ($featured_query->have_posts()) : $featured_query->the_post(); ?>
<?php while (have_posts()) : the_post(); ?>
You need to close your featured posts loop before you open your main loop:
<?php
// Open featured posts loop
while ($featured_query->have_posts()) : $featured_query->the_post();
// Close featured posts loop
endwhile;
// Open main loop
while (have_posts()) : the_post();
?>
You have an extra endif;
after your loop(s):
<?php endwhile;?>
<?php endif; ?>
<div class="clear"></div>
You never call if ( have_posts() )
or if ( $featured_query->have_posts() )
. I would wrap your while
loops inside of if
conditionals, but it's up to you. But if you don't, then get rid of the endif;
Corrected Code
I'm going to give you the bare-bones, and let you add in the meat. Your code should look like so:
<?php
// Define featured posts query
$featured_query = new WP_Query( array(
'posts_per_page' => 3,
'category_name' => 'featured'
) );
// Open featured posts loop
if ( $featured_query->have_posts() ) :
while ( $featured_query->have_posts() ) : $featured_query->the_post();
// Featured posts loop markup goes here
?>
<div class="featureportfolio<?php echo $i++;?>">
<?php etc... ?>
</div>
<?php
// Close featured posts loop
endwhile;
endif;
// Reset post() data
wp_reset_postdata();
// Clear/spacer DIV
?>
<div class="clear"></div>
<?php
// Open the main loop
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Main loop markup goes here
?>
<div id="post-<?php the_ID(); ?>" <?php post_class('post format-standard'); ?>>
<?php etc... ?>
</div>
<?php
// Close main loop
endwhile;
endif;
?>
Note that there's no need to call wp_reset_query()
, since we're not touching the main query.
wp_reset_postdata();
after the loop, whereas your modified version does not – Tom J Nowell♦ Apr 11 '12 at 14:48