我在category.php上有3个查询,我想要对所有循环进行分页,但遗憾的是第一个循环只能正常工作。我已经发现它因为偏移而出现问题,因为当我移除偏移它运行良好但我非常需要抵消帖子。如何纠正我的查询?以下是我的代码。
onReceive
<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>
提前致谢,我们将不胜感激。
答案 0 :(得分:0)
如果您在页面上有多个查询,它们可能会混淆,特别是因为您为每个查询使用相同的PHP变量名称。尝试在每次查询后添加此内容(在&#34; endwhile&#34;之后):
wp_reset_query();
答案 1 :(得分: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' => ' '
)); ?&GT;