把如下代码复制到主题/functions.php
/**
* 针对 The7 "Blog – list" 页面模板强制截取中文摘要
* 解决:文章显示全文、不自动截断、显示 [vc_row] 代码的问题
*/
function force_truncate_blog_list_content( $content ) {
// 1. 仅针对使用 "Blog – list" 模板的页面生效,或者是搜索/归档页
// 同时必须是在主循环中,且不是单篇文章页面
if ( ( is_page_template('template-blog-list.php') || is_archive() || is_search() ) && in_the_loop() && !is_single() ) {
// 2. 清理干扰代码
// 去除 The7 的 Visual Composer 短代码(如 [vc_row]…)
$text = strip_shortcodes( $content );
// 去除 HTML 标签(防止截到一半标签没闭合导致页面乱码)
$text = strip_tags( $text );
// 去除换行符和多余空格
$text = str_replace( array("\n", "\r", "\t"), '', $text );
// 3. 设定截取字数(这里设为 120 字,你可以改)
$length = 200;
// 4. 执行中文截取
if ( mb_strlen( $text ) > $length ) {
$text = mb_strimwidth( $text, 0, $length, '…', 'utf-8' );
// 重新包裹一个 P 标签,保持格式美观
return '<p>' . $text . '</p>';
}
return '<p>' . $text . '</p>';
}
// 对于其他页面(如文章详情页),原样返回,不改动
return $content;
}
// 挂载到 'the_content' 钩子,优先级设高一点 (20) 确保最后执行
add_filter( 'the_content', 'force_truncate_blog_list_content', 20 );
if ( ! defined( 'ABSPATH' ) ) { exit; }






