No duplicate posts with 2 queries
-
The issue that I’m running into is that the sticky post duplicates itself in the second query and populates the first cell of the table. How do I prevent the post from showing up twice?
I’m running a query for all posts in the category ‘tanning’ and displaying the singular sticky post for the category ‘tanning’ with the layout in the ‘firsttext’ div and ‘firstimage’ div, successfully gaining the layout that I’m looking for.
Below that, I’m running a second query for all posts (6 max) that will populate a table, three columns wide, housed in the ‘threeposts’ div, successfully gaining the layout that I’m looking for.
I need this to work with the code below as I don’t want to mess up the formatting. Any help is appreciated!
<div id="firsttext"> <?php if ( get_query_var('paged') ) $paged = get_query_var('paged'); elseif ( get_query_var('page') ) $paged = get_query_var('page'); else $paged = 1; query_posts($ids = array ( 'category_name' => 'tanning', 'posts_per_page' => 1 ) ); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h3 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'responsive'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h3> <div class="post-meta"> <?php responsive_post_meta_data(); ?> <?php the_tags(__('Tagged with:', 'responsive') . ' ', ', ', '<br />'); ?> <?php printf(__('%s', 'responsive'), get_the_category_list(', ')); ?> </div><!-- end of .post-meta --> <div class="post-entry"> <?php the_content(__('...read more.', 'responsive')); ?> <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?> </div><!-- end of .post-entry --> <div class="post-edit"><?php edit_post_link(__('Edit', 'responsive')); ?></div> </div><!-- end of #post-<?php the_ID(); ?> --> <?php endwhile; ?> </div> <div id="firstimage"> <?php if ( has_post_thumbnail()) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <?php the_post_thumbnail(); ?> </a> <?php endif; ?> </div> </div> <?php if ( get_query_var('paged') ) $paged = get_query_var('paged'); elseif ( get_query_var('page') ) $paged = get_query_var('page'); else $paged = 1; query_posts( array ( 'category_name' => 'tanning', 'posts_per_page' => 6 ) ); ?> </div> <div id="threepost"> <table> <?php $col = 0; $cols_per_row = 2; while (have_posts()) : the_post(); if($col == 0) echo '<tr>'; ?> <td class="column'<?php echo $col; ?>" style="vertical-align: top;"> <div class="post" id="post-'<?php the_ID(); ?>'"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('medium'); ?></a> <h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> </div> <div class="post-meta"> <?php responsive_post_meta_data(); ?> <?php the_tags(__('Tagged with:', 'responsive') . ' ', ', ', '<br />'); ?> <?php printf(__('%s', 'responsive'), get_the_category_list(', ')); ?> </div><!-- end of .post-meta --> <div class="entry"><?php the_content('...read more.'); ?> </div> </td> <?php if($col++ >= $cols_per_row){ $col = 0; echo '</tr>'; } endwhile; ?> </table> </div>
- The topic ‘No duplicate posts with 2 queries’ is closed to new replies.