Posted By

verticalgrain on 12/17/11


Tagged

wordpress excerpt gettheexcerpt


Versions (?)

Wordpress excerpt length tag


 / Published in: PHP
 

URL: http://codex.wordpress.org/Function_Reference/get_the_excerpt

function that creates a template tag that can be used to insert excerpts with different lengths. Also controls characters that come after excerpt

  1. // In Functions.php:
  2. function the_excerpt_max_charlength($charlength) {
  3. $excerpt = get_the_excerpt();
  4. $charlength++;
  5. if(strlen($excerpt)>$charlength) {
  6. $subex = substr($excerpt,0,$charlength-5);
  7. $exwords = explode(" ",$subex);
  8. $excut = -(strlen($exwords[count($exwords)-1]));
  9. if($excut<0) {
  10. echo substr($subex,0,$excut);
  11. } else {
  12. echo $subex;
  13. }
  14. echo "[...]";
  15. } else {
  16. echo $excerpt;
  17. }
  18. }
  19.  
  20.  
  21.  
  22.  
  23. // In wordpress template:
  24. <?php the_excerpt_max_charlength(250); ?>

Report this snippet  

You need to login to post a comment.