Return to Snippet

Revision: 54258
at December 17, 2011 06:46 by verticalgrain


Initial Code
// In Functions.php:
function the_excerpt_max_charlength($charlength) {
   $excerpt = get_the_excerpt();
   $charlength++;
   if(strlen($excerpt)>$charlength) {
	   $subex = substr($excerpt,0,$charlength-5);
	   $exwords = explode(" ",$subex);
	   $excut = -(strlen($exwords[count($exwords)-1]));
	   if($excut<0) {
			echo substr($subex,0,$excut);
	   } else {
			echo $subex;
	   }
	   echo "[...]";
   } else {
	   echo $excerpt;
   }
}




// In wordpress template:
<?php the_excerpt_max_charlength(250); ?>

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

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

Initial Title
Wordpress excerpt length tag

Initial Tags
wordpress

Initial Language
PHP