2017-04-02 4 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; 

があなたのショートの内側にこれを追加する前に、右下のコードを追加します。

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"]'); 
post__not_in="'.$post__not_in.'"

を次に最終的なショートは次のようになります

関連する問題