• I’m trying to make a 2 columned newspaper theme that has the main blog posts in the main column, and off to the side a set of posts within a featured category.

    I came across this article within the codex, which i implemented in my theme, but I noticed that the featured category correctly displays a single post as specified in my loop, however the main blog index does not filter out the post in the featured category as it should, rather it displays the post along side other posts.

    I was wondering what may be missing in my loop? I would appreciate your feedback.

    Thanks
    For the featured category this is my code:

    <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
    							  while ($my_query->have_posts()) : $my_query->the_post();
    							  $do_not_duplicate = $post->ID;
    						?>
    							<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    								<h2 id="post-<?php the_ID(); ?>">
    									<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    										<?php the_title(); ?>
    									</a>
    								</h2>
    								<header class="post-data">
    									by <?php the_author() ?>, <?php the_time('F jS, Y') ?>
    								</header>
    								<section class="post-content">
    									<?php the_excerpt();
    									?>
    								</section>
    							</article><!-- end .excerpt -->
    						<?php endwhile; ?>

    and in the main blog index, this is my code:

    <div id="blog">
    						<p class="category"><a href="#" title="Latest News">Latest News:</a></p>
    					   <?php if (have_posts()) : while (have_posts()) : the_post();
    							if( $post->ID == $do_not_duplicate ) continue;
    						?>
    							<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    								<h2 id="post-<?php the_ID(); ?>">
    									<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    										<?php the_title(); ?>
    									</a>
    								</h2>
    								<header class="post-data">
    									by <?php the_author() ?>, <?php the_time('F jS, Y') ?>
    								</header>
    								<section class="post-content">
    									<?php the_excerpt();
    									?>
    								</section>
    							</article><!-- end .excerpt -->
    						 <?php endwhile; endif; ?>
    					</div><!-- end #blog -->

The topic ‘Build a Theme With WP_Query’ is closed to new replies.