Discussion Preview?

KrakKrak New
edited January 2007 in Vanilla 1.0 Help
How hard would it be to get a summary of the post listed on the main page under the topic? Like the first 300 words or so.

Has this been mentioned in any other threads?

I was dabbling around with this a little earlier and was curious. Can it be done with just a simple theme change? Or would it be best to just do it as an extension? I am thinking extension would probably benefit everyone more. I need it for a theme I am working on.

Any ideas? Where would be a good place to start?

Comments

  • Wow, I should have searched harder.

    Not exactly using the same words though.. disregard this post.
  • Did you find an answer on this question?

    Anyone?
  • This has never been done nor, so far as I know, answered with a specific technical tip.
  • That's a pity as I would really need this. Thanks anyway.
  • i am really interested in this too.
  • edited January 2007
    i'm pretty sure that the answer was found in version 0.9.2 of vanilla, so here's something for anyone who wants to work on it

    this isnt a foolproof way but it'll work none the less
    $string = 'find your own string...'; $string = explode(' ', $string); echo implode(' ', array_splice($string, 0, 300));
  • here's a slightly more 'friendly' preview function, dosn't really consider html markup, though...
    function getpreview($text, $len)
    {
    	if(strlen($text) <= $len) return $text;
    	
    	//first check to see if we can seperate paragraphs
    	for($i = $len; $text[$i] != "\n" && $text[$i] != "\r" && $i > 0; $i--) ;
    	for(; $text[$i] == "\r" || $text[$i] == "\n" && $i > 0; $i--) ;
    	if($i > 0) return substr($text, 0, $i + 1);
    	
    	//now try punctuation
    	for($i = $len; !ctype_punct($text[$i]) && $i >= 0; $i--) ;
    	if($i > 0) return substr($text, 0, $i + 1) . ' ...';
    	
    	//and lastly, any spaces
    	for($i = $len; !ctype_space($text[$i]) && $i >= 0; $i--) ;
    	if($i > 0) return substr($text, 0, $i) . ' ...';
    	
    	//if none of the above, just return a substring
    	return substr($text, 0, $len) . ' ...';
    }
  • vincent, sirnot, can you please let us know where to paste the code above? or am i jumping the gun?
  • Is this discussion asking about the same thing as this one?
  • Stash - That post is exactly what I was looking for yes.
This discussion has been closed.