Skip to content

Instantly share code, notes, and snippets.

@theukedge
Last active June 11, 2016 09:50
Show Gist options
  • Save theukedge/7456141 to your computer and use it in GitHub Desktop.
Save theukedge/7456141 to your computer and use it in GitHub Desktop.
Stop posts from showing up multiple times on the same page.
<div id="top-featured" class="clearfix home-block">
<?php
$do_not_duplicate = array();
$my_query = new WP_Query( array(
'post_type' => 'features',
'posts_per_page' => 1
) );
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="above-post">
<div class="date pull-right"><?php echo date( 'M j, Y' ); ?></div>
<h1 class="content-block-title">Today's Top Feature</h1>
</div><!--end post header-->
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div><!--end post-->
<?php $do_not_duplicate[] = $post->ID; ?>
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
</div>
<div class="row-fluid">
<div id="fa-col" class="span6">
<div class="features home-block">
<div class="above-post">
<h2 class="content-block-title">Software Articles</h2>
</div><!--end post header-->
<?php
$my_query = new WP_Query( array(
'category_name' => 'software',
'posts_per_page' => 5,
'post__not_in' => $do_not_duplicate
) );
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry clear">
<h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div><!--end entry-->
<?php $do_not_duplicate[] = $post->ID; ?>
</div>
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment