php - 如何设置 wordpress the_title 的最大长度?
问题描述
我想在 WordPress 高级自定义字段中设置标题的最大长度。
我这样使用但它不起作用:
<p style="position:relative;top:-30px;">
<?php
$post_object_th = get_field('therapeutic_class');
if( $post_object_th ):
$post = $post_object_th;
setup_postdata( $post );
$g_name = get_the_title();
endif;
wp_reset_postdata();
?>
<?php echo wp_trim_words( $g_name, 1 ); ?>
</p>
解决方案
我得到了答案只需使用这个 php 函数substr()
:
<?php echo substr($g_name,0,10).'...';?>
推荐阅读
- c# - 比较来自两个属性的两个列表并将差异添加到第三个列表 C#
- python - 如何使用 python 提取 .xlsm 文件中存在的 MACRO 的名称
- unity3d - 来自 Unity 中采集卡的媒体,带有 Unity 的 Vlc 插件
- ruby-on-rails - 何时在 Ruby on Rails 中使用模型和迁移
- ruby-on-rails - 如何从 ruby 哈希构建 GQL?
- .net - 设置与 CurrentCulture 设置不同的当前线程日期时间格式
- php - Jquery 只读取循环中的第一个元素
- sql - Oracle 数据库 - REF 不受支持的数据类型
- python - 以一对多关系查询
- javascript - FormattedHTMLMessage 在包更新后不起作用(寻找替代/修复)