Posted By

maxxscho on 10/12/11


Tagged

wordpress excerpt


Versions (?)

Wordpress Excerpt Dynamic Length


 / Published in: PHP
 

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

Report this snippet  

You need to login to post a comment.