wordpress 更改excerpt的长度,设置excerpt后面'[...]'的字样和链接

来源:互联网 发布:mac怎么卸载betterzip 编辑:程序博客网 时间:2024/05/22 02:18

wordpress  更改excerpt的长度,设置excerpt后面'[...]'的字样和链接

 (2011-05-12 17:07:10)
转载
标签: 

更改摘要长度

 

excerpt

 

更多字样

 

read

 

more

 

杂谈

分类: wordpress
1、更改系统默认excerpt的长度

默认情况下,excerpt长度设置为55个字,可以使用excerpt_length过滤器改变excerpt的长度,添加如下代码到主题的functions.php文件即可。

function new_excerpt_length($length) {
    return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

2、更改系统默认设置更多样式

excerpt后面更多字符串默认设置为'[...]'。为了改变excerpt的更多字符串形式使用excerpt_more过滤器,添加如下代码在主题的functions.php文件即可。

function new_excerpt_more($more) {
    return '......';
}
add_filter('excerpt_more', 'new_excerpt_more');

对于2.9以上版本使用如下代码:

function new_excerpt_more($excerpt) {
    return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'new_excerpt_more');

3、给文章"read more"添加链接

给文章"read more"添加链接,将如下代码放到主题的functions.php文件。

function new_excerpt_more($more) {

    global $post;
    
    return '<a href="'.get_permalink($post->ID). '">Read the Rest...</a>';
}

add_filter('excerpt_more', 'new_excerpt_more');


源文件:wp_trim_excerpt()在wp-includes/formatting.php.


0

0

阅读(3737) 评论 (3)收藏(0) 转载(1) 喜欢 打印举报
已投稿到:
 排行榜
前一篇:wordpress 通过get_the_excerpt和the_excerpt函数获取文章摘要
后一篇:wordpress 使用wp-postviews统计文章浏览次数和显示热门文章排行的方法
0 0
原创粉丝点击