WordPress Next和Prev帖子 - 按类别混淆

时间:2010-08-11 06:54:39

标签: php wordpress

我为我的single.php模板设置了一个WordPress导航,它可以获得上一个和下一个帖子的缩略图:

    <?php
// Newer posts
$nails_next_post = get_next_post('%link', '', FALSE, 3 );  // Get the previous post
$nails_next_post_thumbnail = get_the_post_thumbnail($nails_next_post->ID); // Get thumbnail
?>

<?php if ($nails_next_post != null) : ?>
<div class="post-nav-next">

   <?php if ($nails_next_post_thumbnail != null): ?>
              <?php echo $nails_next_post_thumbnail; ?>
            <?php else : ?>
              <img src="<?php bloginfo('template_directory'); ?>/images/default-90x90.gif" />
            <?php endif; ?>

         <?php next_post_link('%link', 'Forward' , TRUE, 3 ); ?>

    </div>
<?php endif; ?>


<?php
// Older posts
$nails_prev_post = get_previous_post('%link', '', FALSE, 3 ); // Get the previous post
$nails_prev_post_thumbnail = get_the_post_thumbnail($nails_prev_post->ID); // Get thumbnail
?>

<?php if ($nails_prev_post != null) : ?>
<div class="post-nav-previous">

   <?php if ($nails_prev_post_thumbnail != null): ?>
              <?php echo $nails_prev_post_thumbnail; ?>
            <?php else : ?>
              <img src="<?php bloginfo('template_directory'); ?>/images/default-90x90.gif" />
            <?php endif; ?>

         <?php previous_post_link('%link', 'Back' , TRUE, 3 ); ?>

    </div>
<?php endif; ?>

我遇到的问题是链接继续指向当前帖子类别中的下一个或上一个帖子,而不仅仅是年表中的下一个或上一个帖子(当然,类别3中的帖子除外)。我不在这里。有人有想法吗?谢谢: - )

1 个答案:

答案 0 :(得分:1)

我认为你在get_next_post和get_previous_post函数上使用了错误的参数。你可能不小心使用了next_post_link / previous_post_link

的参数

您只需要两个参数,两者都是可选的: http://codex.wordpress.org/Function_Reference/get_next_post

试试这个:

$nails_next_post = get_next_post();