WordPress模板标签the_excerpt用于输出文章的摘要,需要用在The Loop主循环。如果当前文章有填写“摘要”,the_excerpt()函数输出这个摘要内容,否则自动截断文章内容的前55个字数,中文一个汉字只算作一个字数。
the_excerpt()
函数使用示例
设置截断的字数(写在functions.php里):
function bzg_custom_excerpt_length( $length ) {
return 200;
}
add_filter( 'excerpt_length', 'bzg_custom_excerpt_length', 999 );
在截断的文字后面输出的字符(写在functions.php里):
function bzg_excerpt_more( $more ) {
return '[.....]';
}
add_filter( 'excerpt_more', 'bzg_excerpt_more' );
设置More链接(写在functions.php里):
function bzg_excerpt_more( $more ) {
return sprintf( '%2$s',
get_permalink( get_the_ID() ),
__( 'Read More', 'textdomain' )
);
}
add_filter( 'excerpt_more', 'bzg_excerpt_more' );
扩展阅读
the_excerpt()函数位于:wp-includes/post-template.php
相关函数:
原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/1536.html