大家都知道在博客首页显示日志摘要,利用WordPress为我们提供了自定义Read More(阅读

全文)功能,就可以继续阅读日志全文。

WordPress通过两种方法实现自定义Read More(阅读全文):模板标签 the_excerpt()和 the_content(),因为

the_excerpt()的截取的字符是固定的,无法随心所欲…所以个人比较喜欢the_content(),例如本博客使用的就是:

  1. 控制板”添加新文章”中编辑窗口上方,在需要显示摘要的下方单击”插入More标签”。
  2. 日志中的输出代码:
    <?php the_content(__('阅读全文'));?>

输出的Read More(阅读全文)链接地址是:

<a href="http://www.cndong.cn/2009/12/22.html#more-22">阅读全文</a>

默认是跳转到日志页面摘要的下方!

可是我需要就是跳转到日志页面:

<a href=http://www.cndong.cn/2009/12/22.html>阅读全文</a>

为了达到效果,在主题中的functions.php文件中插入以下代码:

function remove_more_jump_link($link) {
$offset = strpos($link, '#more-');
if ($offset) {
$end = strpos($link, '"',$offset);
}
if ($end) {
$link = substr_replace($link, '', $offset, $end-$offset);
}
return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');

再次打开首页查看日志里的Read More(阅读全文)链接地址源代码看看是不是变回来了啊?!!

One Response to “WordPress自定义Read More(阅读全文)链接地址”

  1. 开心凡人 China China Internet Explorer Internet Explorer 7.0 Windows Windows 7
    December 12th, 2009 16:26

    周末到处看一看,这里挺好呵呵