一般我们添加上一篇和下一篇文章时的代码是这样子的:
<?php previous_post_link('%link','<<') ?> <?php next_post_link('%link','>>') ?>
如果想实现上下篇文章中显示title标签,只需将上面的结构替换成:
<?php $prev_post = get_previous_post(); if (!empty( $prev_post )): ?> <a title="<?php echo $prev_post->post_title; ?>" href="<?php echo get_permalink( $prev_post->ID ); ?>" rel="external nofollow" ><?php echo $prev_post->post_title; ?></a> <?php endif; ?> <?php $next_post = get_next_post(); if (!empty( $next_post )): ?> <a title="<?php echo $next_post->post_title; ?>" href="<?php echo get_permalink( $next_post->ID ); ?>" rel="external nofollow" ><?php echo $next_post->post_title; ?></a> <?php endif; ?>
通过上面的替换,问题就完美解决了。除了可以添加title
属性外,大家如果有需要也可以加上新窗口打开的属性:target:"_blank"
。
此文引自:http://www.jiawin.com/wordpress-tips-previous-next-post-title
One comment