2012-02-01 18 views
1

我想在Wordpress中设置一个循环,它将显示来自一个类别的所有帖子,这是工作得很好,但我的问题是,我的'next_posts_link'和'previous_posts_link'不起作用。他们在页面之间导航就好,但结果始终与第一页相同。为什么我的WordPress的next_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抄本页面,我甚至不认为我的下/上一个环节都能够工作,我希望它的方式。我应该如何处理这个问题?

+1

如果你已经找到了答案,你自己的问题,您必须使用“您的答案”部分并将其标记为已接受,而不是编辑问题。 – 2012-02-01 11:28:22

回答

4

修复了我自己。这篇文章现已解决。经过多次(我的意思是多)谷歌搜索,我发现这篇文章它解决了我的问题: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(); ?> 
+0

答案是在我的答案中发布的代码片段中??!链接就是我从中获得代码的地方。 – egr103 2015-01-22 12:09:37

相关问题