为什么不是';我的Wordpress next_posts_link无法使用排除类别循环


Why isn't my Wordpress next_posts_link not working with exclude category loop?

我正试图在Wordpress中设置一个循环,显示一个类别中的所有帖子,这很好,但我的问题是我的"next_post_link"answers"previous_posts_link"不起作用。它们在页面之间导航很好,但结果始终与第一页相同。

<?php get_header(); ?>
<div id="main" role="main">
<?php
if (is_home()) {
query_posts("cat=-6");} //Exclude work posts (cat 6) from the news page
?>
<div class="inner">
<h1><?php trim(wp_title("")); ?></h1>
<?php include ('sidebartwo.php'); ?>
<section class="main-wrap twocol news">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="box-style">
<time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
<h2><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?>
</a></h2>
<?php the_content(''); ?>
</article>
<?php endwhile; ?>                              
<div class="next-prev-wrap">
<!-- This is what isn't working properly -->
<span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
<span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?>
<!-- /end -->
</span>
</div>
</section>      
<?php endif; ?>
</div> <!-- /inner -->
</div> <!-- /main -->
<?php get_footer(); ?>

我不认为我使用了正确的语法,事实上,根据WP codex页面,我甚至不认为我的下一个/上一个链接能够以我想要的方式工作。我应该如何处理?

修复了我自己。此帖子现已解决。在谷歌上搜索了很多(我的意思是)之后,我发现了这篇文章,它解决了我的问题:http://www.dynamicwp.net/articles-and-tutorials/pagination-problem-when-excluding-certain-category-from-blog-main-page/

作为参考,我的新代码现在看起来像这样:

<?php get_header(); ?>
<div id="main" role="main">
<?php
if (is_home()) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=-6&paged=$paged");
}
?>
<div class="inner">
<h1><?php trim(wp_title("")); ?></h1>
<?php include ('sidebartwo.php'); ?>
<section class="main-wrap twocol news">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="box-style">
<time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
<h2><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>   </h2>
<?php the_content(''); ?>
</article>
<?php endwhile; ?>                              
<div class="next-prev-wrap">
<span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
<span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?></span>
</div>
</section>      
<?php endif; ?>
</div> <!-- /inner -->
</div> <!-- /main -->
<?php get_footer(); ?>