2017-01-18 7 views
0

3つのクエリがcategory.phpにあり、すべてのループに対してページネーションが必要ですが、残念ながら最初のループは動作しています。オフセットを取り除くとうまくいくが、私はひどくポストをオフセットする必要があるので、オフセットのために問題が発生していることがわかった。クエリを修正するにはどうすればよいですか?以下は私のコードです。カテゴリ3のpaginationが動作していません。クエリ

<div class="row" id="CatContent"> 
<div class="col-md-8 col-sm-12"> 
    <div class="leadnewsboxtitle"> 
     <?php 
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
     $category = get_category(get_query_var('cat')); 
     $cat_id = $category->cat_ID; 
     $postquery = new WP_Query(array(
      'post_type' => 'post', 
      'posts_per_page' => 1, 
      'cat' => $cat_id, 
      'paged' => $paged 
     )); 
     while($postquery->have_posts()) : $postquery->the_post(); ?> 
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
      <p><?php read_more(25); ?> ...</p> 
     <?php endwhile; ?> 
    </div> 
</div> 
<div class="col-md-4 col-sm-12 col-xs-12 twoboxlist"> 
    <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $category = get_category(get_query_var('cat')); 
    $cat_id = $category->cat_ID; 
    $postquery = new WP_Query(array(
     'post_type' => 'post', 
     'posts_per_page' => 2, 
     'cat' => $cat_id, 
     'offset' => 1, 
     'paged' => $paged 
    )); 
    while($postquery->have_posts()) : $postquery->the_post(); ?> 
     <div class="col-md-12 col-sm-6 col-xs-6"> 
      <div class="category-news-title"> 
       <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
      </div> 
     </div> 
    <?php endwhile; ?> 
</div> 
<div class="category-news-output"> 
    <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $category = get_category(get_query_var('cat')); 
    $cat_id = $category->cat_ID; 
    $postquery = new WP_Query(array(
     'post_type' => 'post', 
     'posts_per_page' => 9, 
     'cat' => $cat_id, 
     'offset' => 3, 
     'paged' => $paged        
    )); 
    while($postquery->have_posts()) : $postquery->the_post(); ?> 
     <div class="col-md-4 col-sm-6 col-xs-6"> 
      <div class="category-news-title"> 
       <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
      </div> 
     </div> 
    <?php endwhile; ?> 
</div> 

<?php the_posts_pagination(
array(
'prev_text' => __('Prev', 'btimes'), 
'next_text' => __('Next', 'btimes'), 
'screen_reader_text' => ' ' 
)); ?> 

事前に感謝任意の助けが理解されるであろう。

答えて

0

ページに複数のクエリがある場合、それらは混乱する可能性があります。特に、クエリごとに同じPHP変数名を使用しているためです。各クエリの後に(「endwhile」の後に)これ​​を追加してみてください:

wp_reset_query(); 
+0

あなたのコメントをありがとうが、まだ問題に直面しています。私はオフセットのためだと思う。他の解決策を教えてください。 – Mukut

0

私は複数のクエリを使わないで解決策を見つけました。

<div class="row" id="CatContent"> 
<?php 
    $i = 0; 
    while(have_posts()):the_post(); 
     if($i==0) { ?> 
      <div class="col-md-8 col-sm-12"> 
       <div class="leadnewsboxtitle"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
        <p><?php read_more(25); ?> ...</p> 
       </div> 
      </div> 
      <div class="col-md-4 col-sm-12 col-xs-12 twoboxlist"> 
     <?php }elseif($i==1) { ?> 
      <div class="col-md-12 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==2) { ?> 
      <div class="col-md-12 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==3) { ?> 
      </div> 
      <div class="category-news-output"> 
       <div class="col-md-4 col-sm-6 col-xs-6"> 
        <div class="category-news-title"> 
         <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
         <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
        </div> 
       </div> 
     <?php }elseif($i==4) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==5) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==6) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==7) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==8) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==9) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==10) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php }elseif($i==11) { ?> 
      <div class="col-md-4 col-sm-6 col-xs-6"> 
       <div class="category-news-title"> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h2> 
       </div> 
      </div> 
     <?php } 
    $i++; 
endwhile; ?> 
</div> 

<?php the_posts_pagination(array(
'prev_text' => __('আগের খবর', 'btimes'), 
'next_text' => __('পরের খবর', 'btimes'), 
'screen_reader_text' => ' ' 

))。 ?>

関連する問題