wordpress - 特定部分奇怪行为的自定义查询
问题描述
我正在为我的 wordpress 网站使用 elementor pro。我在一页上有 4 个部分,即第 1 节、第 2 节、第 3 节和第 4 节。我的默认摘录限制是 100 个字符。我需要在第 2 节中自定义设置 40 个字符的摘录,所以我将查询 ID(set_excerpt_section_2)放在第 2 节中,并具有以下功能:
add_action( 'elementor_pro/posts/query/set_excerpt_section_2', function( $query ) {
function globalTruncate( $output ) {
global $post;
$chinese_output = preg_match_all("/\p{Han}+/u", $post->post_excerpt, $matches);
if($chinese_output) {
$output = mb_substr($output, 0, 40)." ...";
}
return $output;
}
add_filter( 'get_the_excerpt', 'globalTruncate', 10, 2 );
} );
这 4 个部分的摘录出现在页面上:
第 1 部分:100 个字符(正确:默认为 100 个字符)
第 2 部分:40 个字符(正确)
第 3 部分:40 个字符(这应该是默认的 100 个字符)
第 4 节:40 个字符(这应该是默认的 100 个字符)
请提供任何帮助。
解决方案
推荐阅读
- python-3.x - pymysql 停止工作:NameError: name 'byte2int' is not defined
- sap - 业务对象:替换 sap Bo Universe 中所有未更改的架构名称
- java - Artifactory 未能初始化:上下文为空
- android - 我正在开发一个 android 应用程序,如何通过点击地址进入谷歌地图?使用 Sqlite 的一些代码在这里
- angular - 如何托管多个 Angular 应用程序,使用 nginx 容器进行子域化
- android - EGL 错误:0x3003,相机设备遇到严重错误(Camera2 Api)
- angular - Angular - controlValueAccessor 方法 writeValue() 未被调用
- angular - 在 wwwroot 以外的目录中的 .Net Core 中运行 Angular App
- amazon-web-services - 选择正确的 EC2 实例类型?
- python - 从 bash 重复运行 Python 脚本