WordPress输出文章摘要标签:the_excerpt

本站正在使用的主机

本站目前托管于腾讯云香港轻量服务器,价格便宜访问速度也快,使用本站推荐链接购买还可免费获得WordPress运行环境优化服务。

最新活动 »

WordPress模板标签the_excerpt用于输出文章的摘要,需要用在The Loop主循环。如果当前文章有填写“摘要”,the_excerpt()函数输出这个摘要内容,否则自动截断文章内容的前55个字数,中文一个汉字只算作一个字数。

the_excerpt()

函数使用示例

<?php 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( '<a class="read-more" href="%1$s">%2$s</a>',
        get_permalink( get_the_ID() ),
        __( 'Read More', 'textdomain' )
    );
}
add_filter( 'excerpt_more', 'bzg_excerpt_more' );

扩展阅读

the_excerpt()函数位于:wp-includes/post-template.php

相关函数:

背字根微信二维码

本站文章均为原创,码字非常不容易,转载请注明原文出处,给苦逼的作者保留一点创作动力。