开发者

WordPress Next and Prev posts - confused by categories

I've set up a WordPress navigation for my single.php template that gets the previous and next post's thumbnails like this:

    <?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"开发者_如何学JAVA />
            <?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; ?>

The problem I am having is that the links continue to point to the next or previous post in the current post's category, rather than just the next or previous post in the chronology (except posts in category 3 of course). I'm out of my deoth here. Does anyone have any thoughts? Thanks :-)


I think you are using the wrong parameters on the get_next_post and get_previous_post functions. You probably accidentally used the parameters which go with next_post_link/previous_post_link

You only need two parameters and both are optional: http://codex.wordpress.org/Function_Reference/get_next_post

Simply try this:

$nails_next_post = get_next_post();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜