Duplicate display of featured posts
-
I have a WordPress theme that displays an excerpt of the latest posts from each category. The problem is a lot of my posts are under multiple categories, so the homepage has a bunch of duplicate stories from different categories on it. Here’s a screen shot of the problem:
As you can see, Resident Evil and Star Trek are displayed twice. Is there any way to make it only display one post from each category without creating duplicates? I tried messing with the code but can’t find a solution. Here’s the part of the code that displays the posts:
function xinmag_section_display( $section ) { global $xinmag_options, $xinmag_headlines; $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $xinmag_options['section_postnum'], 'category__in' => $section, 'post__not_in' => $xinmag_headlines, ); $section_posts = new WP_Query( $args ); $count = 0; if ( $section_posts->have_posts() ) { echo '<h3 class="section-title bdcolor_' . $section . '">'; printf( '<a href="%1$s" title="%2$s" class="%3$s">%2$s</a>', get_category_link( $section ) , get_the_category_by_ID( $section ), 'color_' . $section ); echo '</h3>'; $ugly_hack = ""; while ( $section_posts->have_posts() ) { $section_posts->the_post(); echo '<div class="section-item">'; if ( 0 == $count) { if ( has_post_thumbnail() ) { echo '<a href="' . get_permalink() . '">'; the_post_thumbnail( 'xinmag-section', array( 'class' => 'section-image' ,'title' => get_the_title() ) ); echo '</a>'; } echo '<h2 class="section-top"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>'; echo '<div class="entry-summary clearfix">'; the_excerpt(); echo '</div>'; } else echo '<h2 class="section-index"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>'; $count++; echo '</div>'; } } wp_reset_postdata(); }
If it helps to have the theme it’s called Xin Magazine and the file is “/xin-magazine/inc/lib-content.php” lines 300-343.
Thanks, any help would be appreciated!
- The topic ‘Duplicate display of featured posts’ is closed to new replies.