Page 1 of 1
read more
Posted: Sun Jan 08, 2006 1:44 pm
by michu
hey all..
i ve a question.. is there a feature or a plugin, which enables me to "cut down" an blog entry after (for example) 300 chars? and a "<read more...>" will be instertet. i think this would make the overview cleaner...
thanks in advance
michu
ps an example
-----------------
Article 1:
blah blah blah blah
blah blah blah blah
blah blah <read more...>
Article 2:
blah blah blah blah
blah blah blah blah
blah blah <read more...>
-----------------
Re: read more
Posted: Sun Jan 08, 2006 2:24 pm
by garvinhicking
Yes, this comes bydefault with serendipity.That's why our distinction "Entry Body" and "Extended Body" isthere.
Regards,
Garvin
Posted: Sun Jan 08, 2006 3:15 pm
by judebert
The extended entries is the way to go. It allows you to enter only what you want in the overview as the article body, then the rest of the article in the extended body.
If you really want to truncate articles, you'd need to edit your template. In entries.tpl, find
Code: Select all
<div class="serendipity_entry_body">
{$entry.body}
</div>
and change it to
Code: Select all
<div class="serendipity_entry_body">
{if $is_single_entry}
{$entry.body}
{else}
{$entry.body|truncate:300:"<a href='`$entry.link`'>...Read More</a>":false}
{/if}
</div>
That's set up from the Smarty site
http://smarty.php.net/manual/en/languag ... uncate.php, so it ought to work, but when I tried it on my site, I got weird lengths for the truncation.
Maybe I'd better look into upgrading or something. I use the extended entry feature, though.
Good Luck!
Judebert
Posted: Sun Jan 08, 2006 4:04 pm
by garvinhicking
ROTFL.Dang. Ijust wrote something like that in german
See, that happens when people crosspost
Regards,
Garvin
Posted: Wed Jan 18, 2006 2:32 am
by carl_galloway
I've been playing with truncate as well, and I can't figure out why it doesn't actually truncate at the number of characters I specify, for example I might say 50 characters and it seems to randomise this from 39 to 70 characters. Any ideas?
Also, in response to the previous post, be careful about truncating posts in overview mode because the code judebert provided doesn't separate html from text, so if you have an image before entry text, it will truncate somewhere, who knows where, and could totally wreck what you're trying to achieve. Definitely use the extended body instead of smarty script!
I've added a read more to the andreas08 theme I'm working on, which I hope to release soon, but really need to finish my themes checklist and update all themes before I go releasing more new themes. If anyone reads this before I release the theme, either pm me or comment on my blog and I'll send you the instructions to make this work.
Carl
Posted: Wed Jan 18, 2006 8:32 am
by garvinhicking
Hi Carl!
carl_galloway wrote:I've been playing with truncate as well, and I can't figure out why it doesn't actually truncate at the number of characters I specify, for example I might say 50 characters and it seems to randomise this from 39 to 70 characters. Any ideas?
I think truncates cuts at a word boundary. You might need to look up the documentation on
http://smarty.php.net/ to set another parameter that cuts at character boundaries?
Best regards,
Garvin
Posted: Wed Jan 18, 2006 3:31 pm
by judebert
On the other hand, I had the same problem as Carl. When I said 50 words, it cut to around 50 words. Sometimes as little as 10. When I said 300 characters, it got really weird.
I'm not sure what causes it, but I've seen the same thing. Safer to just stick with extended entries.
Posted: Wed Jan 18, 2006 6:17 pm
by carl_galloway
mmm, thing is though, I want to use it to truncate the homelink in the banner. I've been searching out users of my themes and have discovered that quite a few actually use really long post titles, and any theme that uses the homelink could end up being badly thrown out. I thought truncate would solve the problem, and it does, just erratically. Any other thoughts?
Carl