我有一个插件,其中的字符由指定的值限制
使用
wp_html_excerpt($title, $truncatetitlechar)如何通过字数来分隔$title。
我想使用像这样的东西
excerpt($truncatetitlechar)有什么建议吗?
发布于 2012-09-11 05:17:31
假设您正在尝试截断模板文件中的标题,您可以在functions.php中定义一个新函数:
function my_title($insert = '...', $words = 10) {
$title_pieces = explode(' ', get_the_title());
echo implode(' ', array_splice($title_pieces, 0, $words)) . $insert;
}并在循环中调用它,而不是默认的wordpress title函数:
my_title();您还可以在调用函数时将参数传递给该函数,或者更改上述函数中的默认值。第一个参数是添加到修剪后的标题末尾的内容,第二个参数是您希望允许的单词数。
这个答案是this和this的组合。
https://stackoverflow.com/questions/12359213
复制相似问题