Posted By

dottDesign on 05/12/11


Tagged

textmate wordpressphpcustom


Versions (?)

Limit Wordpress Excerpt


 / Published in: Other
 

  1. //Add to functions.php
  2. function excerpt($limit) {
  3. $excerpt = explode(' ', get_the_excerpt(), $limit);
  4. if (count($excerpt)>=$limit) {
  5. array_pop($excerpt);
  6. $excerpt = implode(" ",$excerpt).'...';
  7. } else {
  8. $excerpt = implode(" ",$excerpt);
  9. }
  10. $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
  11. return $excerpt;
  12. }
  13.  
  14. function content($limit) {
  15. $content = explode(' ', get_the_content(), $limit);
  16. if (count($content)>=$limit) {
  17. array_pop($content);
  18. $content = implode(" ",$content).'...';
  19. } else {
  20. $content = implode(" ",$content);
  21. }
  22. $content = preg_replace('/[.+]/','', $content);
  23. $content = apply_filters('the_content', $content);
  24. $content = str_replace(']]>', ']]>', $content);
  25. return $content;
  26. }
  27.  
  28.  
  29. //add instead
  30. <?php echo excerpt(25); ?>
  31. instead of
  32.  
  33. <?php echo excerpt(); ?>

Report this snippet  

You need to login to post a comment.