📜  $trim_length = $custom_field = 'field-name' - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:28.811000             🧑  作者: Mango

代码示例1
$trim_length = 100;  //desired length of text to display
$custom_field = 'my-custom-field-name';
$value = get_post_meta(get_the_ID(), $custom_field, true);
if ($value) {
 $trimmed_value= rtrim(substr($value,0,$trim_length));
 if (strlen($trimmed_value) >= $trim_length)
    $trimmed_value .= " ...";
 echo $trimmed_value;
}