groups

name language licence
WordPress custom post listing PHP BSD
Export WordPress tables PHP BSD
Untitled Snippet Other
Colored CSS Other
SHOW WORDPRESS POST ATTACHMENTS PHP BSD
WORDPRESS GET URL PHP BSD
truncate a wordpress post - PHP - Snipplr PHP BSD
CUSTOM TEMPLATES FOR POSTS IN WORDPRESS PHP BSD

< 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 >



language: PHP
licence: BSD

truncate a wordpress post - PHP - Snipplr

options: view full snippetsend to code collector
//seful if you want to cut off a post at a certain amount of words, since single.php doesn't allow thecontentrss which cuts off at x amount of chars.

<?php
// this can go in functions.php in your theme directory
function word_split_content($words=15) {
$str = get_the_content('');
$a = preg_split("/[\s]+/", $str,$words+1);
$a = array_slice($a,0,$words);
$final_content = join(' ',$a);
echo $final_content;
}
?>
 
<?php get_header(); ?>
 
	
(Continues...)