views:

40

answers:

1

I all,

I have a blog with variying lengths of posts, and I want the homepage to only present the first (let's say) 100 words of the post. After which, it should (automatically) add "more".

What is a good way for doing this with WP 3.0 ?

(I found the "Content and Excerpt Word Limit" plugin: http://wordpress.org/extend/plugins/content-and-excerpt-word-limit/

But:

  1. I see it works for WP 3.0, but could also not.

  2. Since twenty ten theme is a bit more complex, in what way should I add it to the theme ? (add a file called loop-index.php and change it there ?)

+2  A: 

Define something like in the beginning of your WordPress theme's index.php, where $s is your string and $l is the number of words you want:

function cut($s, $l) { 
  if($l<strlen($s)){
    while ($string{$l--} != " ");
    return substr($s, 0, $l+1); 
  } else return $string; 
}

And then say cut(the_content()) instead of the_content() in your loop.

aharon
How will this handle formating ?Let's say it was exactly before a < strong > tag was closed - will it cause problems ?
Tal Galili