我有一个插件,其中字符受指定值限制
使用
wp_html_excerpt($title, $truncatetitlechar)
如何$title
通过字数来分隔。
我想使用类似的东西
excerpt($truncatetitlechar)
有什么建议么?
我有一个插件,其中字符受指定值限制
使用
wp_html_excerpt($title, $truncatetitlechar)
如何$title
通过字数来分隔。
我想使用类似的东西
excerpt($truncatetitlechar)
有什么建议么?
假设您试图截断模板文件中的标题,您可以在 functions.php 中定义一个新函数:
function my_title($insert = '...', $words = 10) {
$title_pieces = explode(' ', get_the_title());
echo implode(' ', array_splice($title_pieces, 0, $words)) . $insert;
}
并在循环中调用它而不是默认的 wordpress 标题函数:
my_title();
您也可以在调用时将参数传递给函数,或者更改上面函数中的默认值。第一个参数是将添加到修剪标题末尾的内容,第二个参数是您希望允许的字数。