WordPress.org

Support

Support » Themes and Templates » Featured posts and avoiding duplicate posts

Featured posts and avoiding duplicate posts

  • Hi

    I am building a theme that involves having one featured article (most recent across all categories). Under this should be the 1st entry for 6 specific categories. However if the featured post is the first post from one of the specific categories it should not display and the 2nd post from that category should display in this box.

    I have it all working apart from the loops for the 6 categories seems to not display any post for that category.

    I have read through the codex and several other tutorials found on the web and on the forums. Can anyone help?

    Loop 1 (Most Recent Article across all categories)

    <?php $my_query = new WP_Query('showposts=1');
    		while ($my_query->have_posts()) : $my_query->the_post();   $do_not_duplicate = $post->ID; ?>  
    
            	<div class="lead-article" id="post-<?php the_ID(); ?>">
    
                	 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                     <h3><?php the_author_posts_link(); ?></h3>
    
                            <div class="entry">
                                <?php the_excerpt('Read the rest of this entry &raquo;'); ?>
                            </div>                 
    
                </div>
    
    		<?php endwhile ?>

    Loop 2 (1st Article from Category 1)

    <?php $my_query = new WP_Query('category_name=author1&showposts=1');
    		while ($my_query->have_posts()) : $my_query->the_post();
    		if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>		        
    
            	<div id="post-<?php the_ID(); ?>">
    
                	 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                     <h3><?php the_author_posts_link(); ?></h3>
    
                </div>        
    
    		<?php endwhile;?>

    Loop 3 (1st Article from Category 2)

    <?php $my_query = new WP_Query('category_name=author2&showposts=1');
    		while ($my_query->have_posts()) : $my_query->the_post();
    		if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>   
    
            	<div id="post-<?php the_ID(); ?>">
    
                	 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                     <h3><?php the_author_posts_link(); ?></h3>
    
                </div>        
    
    		<?php endwhile;?>

    The above loop is then repeated for categoriees 3-6.

    I look forward to your responses.

    Thanks

    Richard

  • The topic ‘Featured posts and avoiding duplicate posts’ is closed to new replies.