$char_number) { $text = substr($text, 0, $char_number); $text = substr($text,0,strrpos($text," ")); $punctuation = ".!?:;,-"; // punctuation you want removed $text = (strspn(strrev($text), $punctuation) != 0) ? substr($text, 0, -strspn(strrev($text), $punctuation)) : $text; $text = $text.$etc; } $text = htmlentities($text, ENT_QUOTES); return $text; } /* Automatically use "single-{category_slug}.php" as post template for that category Example: "single-product.php" is used as template for post with category "product" */ add_filter("single_template", create_function( '$the_template', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-{$cat->slug}.php"; } return $the_template;' ) );