• Hey guys, I have big problem and I’m looking for solution almost a week.

    I have my wordpress page and i want to display two types of posts. featured, 5 normals, featured and 20 normal posts.

    <?php $my_query = new WP_Query('showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; ?>
    
    <div class="featured <?php sandbox_post_class() ?>" >
    <?php include (TEMPLATEPATH . '/post-image.php'); ?>
    <div class="bigdate"><?php the_time('d.m'); ?></div>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    </div><!-- .featured -->
    
    <?php endwhile; ?>
    
    <div class="recent">
    	<?php query_posts('showposts=5'); ?>
    	<?php while (have_posts()) : the_post();
    		  if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    	<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
    
    	<?php include (TEMPLATEPATH . '/post-image.php'); ?>
    
    	<div class="bigdate"><?php the_time('d.m'); ?></div>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    	</div><!-- .post -->
    
    <?php endwhile ?>

    But when I’m putting code (featured with showposts=1) after second while, it’s looking good, but with duplicated posts from featured.

    How to fix it, that featured will be using second post, not the same from previous while?

    Any idea to sove it? ??

    Thank you so much

Viewing 9 replies - 1 through 9 (of 9 total)
  • Apologies, I’m having a bit of trouble totally understanding this. Is this a plugin or part of your theme?

    So when you run this, you get 1 post displayed twice, is that right?

    Thread Starter Marcin

    (@k0n0pka)

    It’s just part of theme.

    Exactly, when I’m using “featured” or “recent” class, posts are duplicated.

    please post the full code of the template, with all loops;
    use the pastebin – https://codex.www.ads-software.com/Forum_Welcome#Posting_Code

    Thread Starter Marcin

    (@k0n0pka)

    https://pastebin.com/4FebD5HZ
    https://pastebin.com/JNDWkSif

    The problem is that second use of displaying “recent” posts arent working good. How to fix that duplicating ? ??

    second use of displaying “recent” posts arent working good. How to fix that duplicating ?

    on a basic level, you could use the ‘offset’ parameter in the query:
    https://codex.www.ads-software.com/Class_Reference/WP_Query#Pagination_Parameters
    although this will make problems with pagination.

    to edit the code, I would need to know:
    are you using the ‘sticky’ posts as ‘featured’?
    and do you have two ‘sticky’ posts or more?
    and do you want to exclude the ‘sticky’ posts from the ‘recent’ posts?

    Thread Starter Marcin

    (@k0n0pka)

    are you using the ‘sticky’ posts as ‘featured’? no
    and do you have two ‘sticky’ posts or more? i dont have even 1 sticky post

    featured post = normal post with bigger photo
    recent post = normal post with smaller photo

    its not about sticky.

    —–

    and i want to fix that code to display for example 1 post with bigger photo as featured, then 3 as recent post, then again featured etc…

    Thread Starter Marcin

    (@k0n0pka)

    <?php $my_query = new WP_Query('showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; ?>
    
    <div class="featured <?php sandbox_post_class() ?>" >
    <?php include (TEMPLATEPATH . '/post-image.php'); ?>
    <div class="bigdate"><?php the_time('d.m'); ?></div>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    </div><!-- .featured -->
    <?php endwhile; ?>
    
    <div class="recent">
    	<?php query_posts('showposts=7'); ?>
    	<?php while (have_posts()) : the_post();
    		  if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);?>
    	<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
    
    	<?php include (TEMPLATEPATH . '/post-image.php'); ?>
    
    	<div class="bigdate"><?php the_time('d.m'); ?></div>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    	</div><!-- .post -->
    
    <?php endwhile ?>
    </div>
    <!-- .recent -->
    
    <div class="featured <?php sandbox_post_class() ?>" >
    <?php include (TEMPLATEPATH . '/post-image.php'); ?>
    <div class="bigdate"><?php the_time('d.m'); ?></div>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    
    </div><!-- .featured -->
    
    <div class="recent">
    	<?php query_posts('showposts=5'); ?>
    	<?php while (have_posts()) : the_post();
    		  if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);?>
    	<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
    
    	<?php include (TEMPLATEPATH . '/post-image.php'); ?>
    
    	<div class="bigdate"><?php the_time('d.m'); ?></div>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    	</div><!-- .post -->
    
    <?php endwhile ?>

    With that code, displaying looks like that:
    https://img853.imageshack.us/img853/25/duplicatedpostsproblem.png

    but I want to display id’s 1,2,3,4,5……

    it might be easier to knock everyting into one loop, and use the loop counter $my_query->current_post to style the featured posts different;

    example:

    <?php $my_query = new WP_Query('posts_per_page=14&paged='.get_query_var('paged'));
      while ($my_query->have_posts()) : $my_query->the_post();
    
    if( $my_query->current_post == 0 || $my_query->current_post == 7 ) : ?>
    
    <div class="featured <?php sandbox_post_class() ?>" >
    <?php include (TEMPLATEPATH . '/post-image.php'); ?>
    <div class="bigdate"><?php the_time('d.m'); ?></div>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    </div><!-- .featured -->
    
    <?php else : ?>
    
    <div id="post-<?php the_ID() ?>" class="recent <?php sandbox_post_class() ?>">
    <?php include (TEMPLATEPATH . '/post-image.php'); ?>
    
    <div class="bigdate"><?php the_time('d.m'); ?></div>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="post-content"><?php the_title() ?><span class="post-content-excerpt"><?php the_excerpt(); ?></span></a>
    </div><!-- .post -->
    
    <?php endif; ?>
    
    <?php endwhile;
    wp_reset_postdata(); ?>

    the above code removes the div .recent, and moves the css class to the post; you might need to adapt your css.

    bare minimum css:

    .recent { width: 24%; float: left; margin-left: 1%; }
    .featured { width: 49%; float: left; margin-left: 1%; }

    Thread Starter Marcin

    (@k0n0pka)

    wow it’s working perfectly! thank you so much! ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Duplicating posts even with do_not_duplicate’ is closed to new replies.