开发者

Wordpress return newlines

When a user searches on my wordpress site, the_excerpt is called to display the search results, however all new lines from my original post are removed. I have tried modifying the wp_trim_excerpt function, however the $text passed to this function already has all new lines removed.

Essentially, I want the_excerpt to retain new lines from my blog post when displaying the results information.

Does anyone know how to do thi开发者_Go百科s?


what you could do is use the_content() instead of using the_excerpt, which for all accounts strips all styling from the text,

then use a little function like this in your functions.php file

<?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;
} 
?>

then in your theme, or were you want the text to apear just make a call to that function

<?php
  $text = the_content();
  echo truncateText($text, 250);
?>

hopfully should point you in the right direction..

Marty

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜