• First of all im using 2 query post in front page. One is for sticky post one for regular post loop. And i also using inifnity page scrolling in fronpage.

    Problem is : After next page in second loop two posts are duplicating . Cant find any solution in internet please help.

    First loop for 3 sticky post showing diffrent

    <?php
         $sticky = get_option( 'sticky_posts' ); // Get all sticky posts
         rsort( $sticky ); // Sort the stickies, latest first
         $sticky = array_slice( $sticky, 0, 3 ); // Number of stickies to show
         query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); // The query?>
    
    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>
    <?php if ($count == 1) : ?>
      <div class="top_story col-lg-8 col-md-7 col-xs-7">
      	<div class="loop-post-content clearfix">
      		<div class="article-featured-image has-sharer">
      			<a href="<?php the_permalink() ?>" ><?php
        if ( has_post_thumbnail() ) {
            the_post_thumbnail( 'homepage-thumb' );
        }
    ?></a>
      		</div><!----article-image-->
    
      		<div class="article-head">
      			<div class="loop-post-byline">
      				<span class="date">Нийтлэгч</span>
      				<span class="author_sticky"><?php the_author_posts_link(); ?></span>
      				<span class="date">—<?php the_time('Y.m.d ') ?> </span>
      			</div>
      			<div class="article-headline">
                <h1 class="article-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
                </div>
            </div><!----article-head-->
    
            <div class="article-excerpt">
            	<p><?php echo substr(get_the_excerpt(), 0,300); ?><a class="sticky_more" href="<?php the_permalink() ?>">?ргэлжлэл→</a></p>
    
            </div><!----excerpt-->
    
         </div>
       </div>
        <?php elseif ($count == 2) : ?>
        	<div class="top-story-side col-lg-4 col-md-5 col-xs-5">
        	  <div class="loop-post">
        	  	<div class="loop-post-image">
        	  			<a href="<?php the_permalink() ?>" ><?php
        if ( has_post_thumbnail() ) {
            the_post_thumbnail( 'homepage-thumb' );
        }
    ?></a>
        	  	</div><!--- image-loop-->
    
        	  	<div class="loop-post-content clearfix">
        	  		<div class="loop-post-byline">
        	  			<span class="date"><?php the_time('Y.m.d ') ?> </span>
        	  			<span class="author_sticky">— <?php the_author_posts_link(); ?></span>
        	  		</div><!--- byline-->
    
                 <h2 class="featured-title"><a class="post-link" href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
            </div><!--- contet loop-->
    
            </div><!--- looppost-->
        <?php elseif ($count == 3) : ?>
    
      <div class="loop-post">
        	  	<div class="loop-post-image">
        	  			<a href="<?php the_permalink() ?>" ><?php
        if ( has_post_thumbnail() ) {
            the_post_thumbnail( 'homepage-thumb' );
        }
    ?>
    </a>
        	  	</div><!--- image-loop-->
    
        	  	<div class="loop-post-content clearfix">
        	  		<div class="loop-post-byline">
        	  			<span class="date"><?php the_time('Y.m.d ') ?> </span>
        	  			<span class="author_sticky">— <?php the_author_posts_link(); ?></span>
        	  		</div><!--- byline-->
    
                 <h2 class="featured-title"><a class="post-link"  href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
            </div><!--- contet loop-->
    
            </div><!--- looppost-->
    
        </div>
        </div><!--- top_story-->
    
        <?php else : ?>
    
        <?php endif; ?>
    
         <?php endwhile;   ?>
         <?php endif; ?>
    
    </div>

    2. Second loop for rest of regular post

    <?php
    // Get the ID of a given category
    $category_id = get_cat_ID( 'Category Name' );
    
    // Get the URL of this category
    $category_link = get_category_link( $category_id );
    
    ?>
    
    <?php
    $args = array(
        'posts_per_page' => 9,
        'ignore_sticky_posts' => 1
    );
    
    $the_query = new WP_Query( $args );
    ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); 
    
    $do_not_duplicate = $post->ID; ?>
    
    			<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 one-post clearfix" id="post-<?php the_ID(); ?>">
    	<div class="one-meta">
    	      <div class="date"><i class="glyphicon glyphicon-time meta"></i> <?php the_time('Y.m.d ') ?> </div>
    	      <div class="one-cat " >
    	      	<i class="glyphicon glyphicon-tags" style="margin-right:5px; font-size:0.7em;"></i>
    <?php the_category(', ') ?>
       	      </div>
       </div>
    
    		<div class="one-img view view-first">
    			<a href="<?php the_permalink() ?>" ><?php
        if ( has_post_thumbnail() ) {
            the_post_thumbnail( 'homepage-thumb' );
        }
    ?></a>
     <div class="mask">
         <h2><i class="glyphicon glyphicon-user front_author" ></i><?php the_author_posts_link(); ?></h2>
         <p><i class="glyphicon glyphicon-eye-open front_eye"></i><?php echo getPostViews(get_the_ID()); ?></p>
             <a href="<?php the_permalink() ?>" class="info">Дэлгэрэнг?й</a>
         </div>
    </a>
    		</div>		
    
    	    <h2 class="one-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    </div>
    
    		<?php endwhile; endif; ?>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m guessing what you think ‘ignore_sticky_posts’ does is not what it does. It does not suppress retrieving stickies, it controls whether they are moved to the top or not.

    It’s not clear to me why you don’t just run a single query and let the stickies float to the top as they would naturally do. Maybe it’s the infinite scrolling. No matter, I can answer your question.

    The first query loop needs to accumulate all post IDs returned into an array. That array is then used for the ‘post__not_in’ argument of the second query.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom loops, sticky posts, and pagination duplicate in next page’ is closed to new replies.