我想在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).'...';?>