Posted By

Omegakenshin on 12/31/11


Tagged

wordpress content excerpt


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

zemonte


Multiple excerpt lengths in wordpress


 / Published in: PHP
 

URL: http://stackoverflow.com/questions/4082662/multiple-excerpt-lengths-in-wordpress

then in your template code you just use..

echo excerpt(25);

  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. }

Report this snippet  

You need to login to post a comment.