当用户在我的wordpress站点上搜索时,调用_摘录来显示搜索结果,但是从我的原始帖子中删除所有新的行。我已经尝试修改wp_trim_摘录函数,但是传递给该函数的$text已经删除了所有新行。
本质上,我希望the_摘录在显示结果信息时保留博客文章中的新行。
有人知道怎么做吗?
你可以做的是使用the_content()而不是使用the_摘录,这对于所有帐户从文本中删除所有样式,
然后在functions.php文件
中使用如下的小函数<?php
function truncateText($content, $chars = 150) {
// Change to the number of characters you want to display
$content= $content." ";
$content= substr($content,0,$chars);
$content= substr($content,0,strrpos($content,' '));
$content= $content."...";
return $content;
}
?>
然后在你的主题中,或者你想要文本出现只需调用该函数
<?php
$text = the_content();
echo truncateText($text, 250);
?>
希望能给你指明正确的方向。
马蒂