admin管理员组文章数量:1026989
Here is my situation, if you look at the following page: /, you will see that the pagination is not working. After researching the problem, I found the problem within the following code:
foreach ($categories as $cat) {
$cat_id = $cat->term_id;
if($cat->name != 'Uncategorized' && $cat->name != 'Hero') :
$catURL = get_category_link($cat_id);
echo "<div class='side-cat'><button>".$cat->name."</button><ul>";
query_posts("cat=$cat_id&posts_per_page=5");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<li><a href="<?php echo $catURL; ?>" title="Read All <?php echo $cat->name; ?> Stories">More. . .</a></li>
</ul></div>
<?php endif; } ?>
The main culprit was the query_posts. Is there an alternative to the query posts so it doesn't interfere with the pagination?
I'm using Wordpress 5.1
Thank you, Kevin Davis
Here is my situation, if you look at the following page: http://staging.cancerwellness/mind-body/cancerversary/, you will see that the pagination is not working. After researching the problem, I found the problem within the following code:
foreach ($categories as $cat) {
$cat_id = $cat->term_id;
if($cat->name != 'Uncategorized' && $cat->name != 'Hero') :
$catURL = get_category_link($cat_id);
echo "<div class='side-cat'><button>".$cat->name."</button><ul>";
query_posts("cat=$cat_id&posts_per_page=5");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<li><a href="<?php echo $catURL; ?>" title="Read All <?php echo $cat->name; ?> Stories">More. . .</a></li>
</ul></div>
<?php endif; } ?>
The main culprit was the query_posts. Is there an alternative to the query posts so it doesn't interfere with the pagination?
I'm using Wordpress 5.1
Thank you, Kevin Davis
Share Improve this question asked Mar 29, 2019 at 15:31 Kevin DavisKevin Davis 1071 gold badge2 silver badges6 bronze badges 1- Query_posts is specifically designed to alter the main page query. For additional queries, you can create addition WP_Query objects and operate on them instead. – tmdesigned Commented Mar 29, 2019 at 16:44
1 Answer
Reset to default 0query_posts()
is going to alter the main query, and it doesn't sound like you want that. I would recommended using the WP_Query
object to get the other posts.
That said, if you must use query_posts()
, call wp_reset_query()
at the end of your foreach
to reset your main query back to the original one.
Here is my situation, if you look at the following page: /, you will see that the pagination is not working. After researching the problem, I found the problem within the following code:
foreach ($categories as $cat) {
$cat_id = $cat->term_id;
if($cat->name != 'Uncategorized' && $cat->name != 'Hero') :
$catURL = get_category_link($cat_id);
echo "<div class='side-cat'><button>".$cat->name."</button><ul>";
query_posts("cat=$cat_id&posts_per_page=5");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<li><a href="<?php echo $catURL; ?>" title="Read All <?php echo $cat->name; ?> Stories">More. . .</a></li>
</ul></div>
<?php endif; } ?>
The main culprit was the query_posts. Is there an alternative to the query posts so it doesn't interfere with the pagination?
I'm using Wordpress 5.1
Thank you, Kevin Davis
Here is my situation, if you look at the following page: http://staging.cancerwellness/mind-body/cancerversary/, you will see that the pagination is not working. After researching the problem, I found the problem within the following code:
foreach ($categories as $cat) {
$cat_id = $cat->term_id;
if($cat->name != 'Uncategorized' && $cat->name != 'Hero') :
$catURL = get_category_link($cat_id);
echo "<div class='side-cat'><button>".$cat->name."</button><ul>";
query_posts("cat=$cat_id&posts_per_page=5");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<li><a href="<?php echo $catURL; ?>" title="Read All <?php echo $cat->name; ?> Stories">More. . .</a></li>
</ul></div>
<?php endif; } ?>
The main culprit was the query_posts. Is there an alternative to the query posts so it doesn't interfere with the pagination?
I'm using Wordpress 5.1
Thank you, Kevin Davis
Share Improve this question asked Mar 29, 2019 at 15:31 Kevin DavisKevin Davis 1071 gold badge2 silver badges6 bronze badges 1- Query_posts is specifically designed to alter the main page query. For additional queries, you can create addition WP_Query objects and operate on them instead. – tmdesigned Commented Mar 29, 2019 at 16:44
1 Answer
Reset to default 0query_posts()
is going to alter the main query, and it doesn't sound like you want that. I would recommended using the WP_Query
object to get the other posts.
That said, if you must use query_posts()
, call wp_reset_query()
at the end of your foreach
to reset your main query back to the original one.
本文标签: Query Post interferes with Pagination
版权声明:本文标题:Query Post interferes with Pagination 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745645322a2160989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论