2017-04-02 128 views
0

我正在一個頁面上有多個部分的網站上工作,每個部分有多個循環包含多個類別。我使用Ajax Load More插件爲每個部分加載新帖子。問題是當我點擊加載更多時,它加載已經顯示的帖子和未顯示的帖子。我希望它只加載尚未顯示的新帖子。AJAX加載更多的插件負載已顯示的帖子

這裏是我使用的簡碼:

echo do_shortcode('[ajax_load_more container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]'); 

這裏是環路上的部分

<div class="row"> 

       <div class="col-lg-12 col-sm-12"> 
        <div class="music_box bg-color1"> 
         <div class="music_box_top"> 

          <?php 
          $sticky = get_option('sticky_posts'); 
          rsort($sticky); 

          $args = array(
           'post__in' => $sticky, 
           'posts_per_page' => 1, 
           'cat' => 34 
           ); 

          $sticky_query = new WP_Query($args); 

          while ($sticky_query->have_posts()) : $sticky_query->the_post(); 
          ?> 
          <a href="<?php the_permalink(); ?>"> 
           <div class="fashion_box_thumb"> 
            <?php 
            if (has_post_thumbnail()) { 
             the_post_thumbnail('full', array()); 
            } 
            ?> 
           </div> 
          </a> 

          <div class="fashion_box_text"> 
           <a href="<?php the_permalink(); ?>"> 
            <h3><?php the_title(); ?></h3> 
           </a> 
           <p><?php the_excerpt(); ?></p> 

           <div class="post_cont_icons"> 
            <span class="fa fa-comments cmnt"> <?php comments_number('0','1','%'); ?></span> 
            &nbsp; &nbsp;   
            <?php echo getPostLikeLink(get_the_ID());?> 

            <span class="matchtime2"><i class="fa fa-clock-o"></i> <?php the_time();?><br></span> 
           </div> 

          </div> 


          <?php endwhile; ?> 
          <?php wp_reset_postdata(); ?> 

          <div class="clear"></div> 

         </div><!--music_box_top--> 

         <div class="fashion_box_bottom"> 

          <?php 
          $args = array(
           'post__not_in' => get_option('sticky_posts'), 
           'posts_per_page' => 4, 
           'cat' => 34 
           ); 

          $sticky_query = new WP_Query($args); 

          $count = 0; 

          while ($sticky_query->have_posts()) : $sticky_query->the_post(); ?> 
           <?php $count++; ?> 
           <?php if ($count == 1) : 
          ?> 

          <div class="fashion_box_bottom_item"> 
           <a href="<?php the_permalink(); ?>"> 
            <h4><?php the_title(); ?></h4> 
           </a> 
          </div> 

          <?php elseif ($count == 2) : ?> 
          <div class="fashion_box_bottom_item"> 
           <a href="<?php the_permalink(); ?>"> 
            <h4><?php the_title(); ?></h4> 
           </a> 
          </div> 

          <?php elseif ($count == 3) : ?> 
          <div class="fashion_box_bottom_item"> 
           <a href="<?php the_permalink(); ?>"> 
            <h4><?php the_title(); ?></h4> 
           </a> 
          </div> 

          <?php elseif ($count == 4) : ?> 
          <div class="fashion_box_bottom_item"> 
           <a href="<?php the_permalink(); ?>"> 
            <h4><?php the_title(); ?></h4> 
           </a> 
          </div>       

          <div class="clear"></div> 

         </div><!--music_box_bottom--> 
        </div><!--music_box--> 
       </div><!--col-lg-12--> 

       <?php else : 
       get_template_part('woodclefpro/pro_template3'); 

       endif; 
       endwhile; 
       wp_reset_postdata(); ?> 

      </div><!--row--> 
      <div class="row"> 
      <?php 

       echo do_shortcode('[ajax_load_more container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]'); 
      ?> 
      </div> 

回答

0

這對於那些可能會遇到上述問題,都面臨着同樣的問題,我是。這是我如何解決它。

添加下面右邊的代碼之前endwhile

$do_not_duplicate[] = $post->ID; 

添加這是你的簡碼內:post__not_in="'.$post__not_in.'"

然後最終簡碼如下:

echo do_shortcode('[ajax_load_more ajax_load_more post__not_in="'.$post__not_in.'" container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');