上一篇、下一篇文章代码:
<?php previous_post_link('%link','<<') ?>
<?php next_post_link('%link','>>') ?>
|
该代码解析出来的代码大概如下:
<a href="……" rel="external nofollow" rel="external nofollow" > …… </a>
<a href="……" rel="external nofollow" rel="external nofollow" > …… </a>
|
通过 get_previous_post、get_next_post 这两个函数我们可以获取到上一篇和下一篇文章的相关信息(大家可以到官网看看这两个函数的介绍)。
具体解决方法如下:
将
<?php previous_post_link('%link','<<') ?>
<?php next_post_link('%link','>>') ?>
|
替换为
<?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; ?>
|