首页 » PHP教程 » phphtml摘要技巧_wordpress运用the_excerpt函数显示文章的摘要信息

phphtml摘要技巧_wordpress运用the_excerpt函数显示文章的摘要信息

访客 2024-12-09 0

扫一扫用手机浏览

文章目录 [+]

函数用法

the_excerpt();

phphtml摘要技巧_wordpress运用the_excerpt函数显示文章的摘要信息

每每利用默认的是无法知足我们的需求的,因此须要对此改造。

phphtml摘要技巧_wordpress运用the_excerpt函数显示文章的摘要信息
(图片来自网络侵删)

修正择要的长度

默认是55个字符,我们可以利用excerpt_length过滤器钩子改变择要(excerpt)的长度,代码如下:

function new_excerpt_length($length) {

return 150;

}

add_filter('excerpt_length', 'new_excerpt_length');

修正择要末端的显示

择要末端附加的字符串默认设置为[…],修正末端的显示可以用excerpt_more过滤器钩子,代码如下:

function new_excerpt_more($more) {

return '...';

}

add_filter('excerpt_more', 'new_excerpt_more');

末端加阅读更多

function new_excerpt_more($more) {

global $post;

return '…[阅读更多]';

}

add_filter('excerpt_more', 'new_excerpt_more');

将以上代码加入到function.php中即可。

标签:

相关文章