Sticky/Featured Post/Avoiding Duplicates
-
I’ve been wrecking my brain over this – but it may not be as complicated for someone with more programming skill.
Here’s what I have..
1. A category page with 2 columns. The left column holds 2 featured posts, the right column holds “other posts” in this category.
2. 2 categories – one being the regular topic, the other one for featured posts within this topic (ie. Category A, Category A-Featured)
3. Posts in the left column are assigned to both the regular topic as well as the featured category (Category A, Category A-Featured), posts in the right column just to the topic (Category A)
4. Featured posts are not necessarily the most recent ones, but rather a hand-picked selection of cornerstone content within the specific topic.
The challenge I have is to present the content in both left and right columns and primary to prevent posts to show up twice on this page.
Here’s what I have…
Left Featured Column – pulling in the first featured post and making sure it’s not replicated elsewhere.
Loop 1:
<?php $recent = new WP_Query("cat=A-Featured&showposts=1"); while($recent->have_posts()) : $recent->the_post(); $do_not_duplicate = $post->ID; ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2> <?php the_content(__('more »'));?> <?php endwhile; ?>
Then, we grab the second featured article, making sure it’s not the same as the first post and making sure it’s not replicated elsewhere on the page:
Loop 2:
<?php $recent = new WP_Query("cat=A-Featured&showposts=2"); while($recent->have_posts()) : $recent->the_post(); if ( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); $do_not_duplicate = $post->ID; ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2> <?php the_content(__('more »'));?> <?php endwhile; ?>
And lastly, we take the the right column and start our third loop – making sure the posts have not been printed elsewhere on the page already.
Loop 3:
<?php $recent = new WP_Query("cat=A&showposts=9"); while($recent->have_posts()) : $recent->the_post(); if( $post->ID == $do_not_duplicate) continue; update_post_caches($posts); ?> <b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b> <?php the_content_limit(130, ""); ?> <?php endwhile; ?>
This works great – with one problem; the first featured posts still appears in the list of “rest posts” in the right column.
Any ideas on how I can fix this? I have a feeling it’s relatively simple, but I can’t seem to come up with an answer.
Thanks in advance,
John
- The topic ‘Sticky/Featured Post/Avoiding Duplicates’ is closed to new replies.