【发布时间】:2023-04-08 06:44:01
【问题描述】:
我有一个功能可以将标题修剪到一定长度。它确实正确地修剪了标题,但即使标题没有超过长度,它也总是显示“...”。
有谁知道怎么做,所以“...”只会在标题太长时显示?
// Title Excerpt//
function the_titlesmall($before = '', $after = '', $echo = true, $length = false) { $title = get_the_title();
if ( $length && is_numeric($length) ) {
$title = substr( $title, 0, $length );
}
if ( strlen($title)> 0 ) {
$title = apply_filters('the_titlesmall', $before . $title . $after, $before, $after);
if ( $echo )
echo $title;
else
return $title;
}
}
//End Title Excerpt
PHP 在循环中
<?php the_titlesmall('', '', true, '15') ?>
【问题讨论】:
-
能否在显示时使用 CSS 的
text-overflow: ellipsis而不是摆弄实际数据来解决您的问题?