• 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:

    View post on imgur.com

    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Rub3X

    (@rub3x)

    Looks like you’ll also need magazine.php to figure this out. I read the code and it looks like I should be able to change foreach ( $sections[‘section’] as $section ) {

    to

    while ($x < 10) {

    and it should work. And it does…except it doesn’t put the stories in different columns, it puts it all in a single column…

    wp_reset_postdata();
    	$sections = array();
    	parse_str( $xinmag_options['section_order'], $sections );
    	$col = 0;
    	$column = 3;
    	foreach ( $sections['section'] as $section ) {
    		if ( $column > 1 && $col == 0 )
    			echo "\n" . '<div class="row">';
    		echo "\n" .'<div id="section-' . $section . '" class="section-home large-4 columns">';
    		$col = $col + 1;
    		if ( $col == 3 )
    			$col = 0;
    		xinmag_section_display( $section );
    		echo '</div>';
    		if ( $col == 0 )
    			echo '</div><!-- row -->';	 //row
    	}
    	if ( $col > 0 )
    		echo '</div><!-- row -->';
    ?>
    </div><!-- content -->

    Hi,
    I have a question about xin magazine theme too, I’m testing it now and I would like to have more then 3 titles in one category on the homepage, for now it’s only 3 visible titles on homepage is there a chance to change that?
    I will be grateful for the help!
    Cheers ??

    Thread Starter Rub3X

    (@rub3x)

    If you’re asking what I think you’re asking, go to Appearence -> Theme options -> Sections

    There you can pick and choose which categories show up on the home page and customize their colors.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Duplicate display of featured posts’ is closed to new replies.