ls smart blog excerpt


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $content = $post->content;
  2.  
  3. if(preg_match_all('#<p>(.*)</p>#simU', $content, $m1, PREG_SET_ORDER) && count($m1) >= 2) { // more than 2 paragraphs
  4. $trim = $site_settings->blog->preview->trim_length;
  5. $l_1 = strlen($m1[0][1]);
  6. $l_2 = strlen($m1[1][1]);
  7.  
  8. if($l_1 < ($trim * 0.75) && $l_2 < $trim) {
  9. $content = '<p>' . $m1[0][1] . '</p>' . '<p>' . $m1[1][1] . '</p>';//substr($content, 0, $l_1 + $l_2 + 7 + 7 + 2);
  10. }
  11. else if($l_1 < $trim) {
  12. $content = '<p>' . $m1[0][1] . '</p>'; //substr($content, 0, $l_1 + 7);
  13. }
  14. else {
  15. $content = '<p>' . substr($m1[0][1], 0, $trim) . ' ...</p>';
  16. }
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.