Page 1 of 1
Shortening entries only on main page
Posted: Mon Jul 21, 2008 5:15 pm
by metalcoat
Is there any plugin/setting to shorten the entries on the main page. I still want the full entry once the entry is opened.
Thanks in advanced.
Posted: Mon Jul 21, 2008 6:05 pm
by judebert
There isn't a plugin to do this, at least as far as I'm aware.
However, this "teaser" functionality is built-in to Serendipity.
On the entry editing page, there are two fields: one is the entry body, where you type the "teaser" or short article. This will appear on your front page.
The second is the "extended body", where you type the rest of the entry. This will appear only when you display the full entry.
You could also modify your template to truncate the entry after a given number of characters, but you'll have to use |@strip_tags to ensure you don't split something in the middle of an HTML tag. And then you lose all your formatting. It's a lot easier to use the entry/extended bodies to break the short preview exactly where you want it.
Posted: Mon Jul 21, 2008 10:17 pm
by metalcoat
This isn't exactly what I had in mind, however will work, but that makes sense what you say. I guess I just didn't get what the extended part meant at first.
Thanks for replying so quickly.
Posted: Tue Dec 16, 2008 3:27 pm
by 3nd3r
judebert wrote:You could also modify your template to truncate the entry after a given number of characters, but you'll have to use |@strip_tags to ensure you don't split something in the middle of an HTML tag. And then you lose all your formatting.
Sorry for bump this not-too-old post, but that's exactly what I want!
Can you tell me how could I make it?
Thanks in advance for your time!
Posted: Tue Dec 16, 2008 4:06 pm
by Don Chambers
Lets see if I understand - you do NOT want to use the built-in ability to place "teaser text" into the entry body, and the rest of the entry into the extended entry body?
If so, I'll use bulletproof as an example.
The file rendering entries, whether they are overview or detailed is entries.tpl.
The "teaser" block (as Judebert called it) is here:
Code: Select all
<div class="entry-content serendipity_entry_body">
{$entry.body}
To truncate that to, say 400 characters, AND strip any possible html from it, and add 3 dots after it if it was truncated, you would change it to this:
Code: Select all
<div class="entry-content serendipity_entry_body">
{$entry.body|@strip_tags|@strip|@truncate:400:" ..."}
Posted: Tue Dec 16, 2008 5:02 pm
by 3nd3r
Thank you Don! That almost do what I want!
I mean "almost" because:
1) Yes, it removes all html... but that's not what I want, because it removes break lines, images, embed videos... So, I've deleted the '|@striptags' part of the code. If on an entry in particular I'd see that the HTML has been broken, I'd go to edit it to avoid this. This is the code I'm using:
Code: Select all
<div class="serendipity_entry_body"> {$entry.body|@strip|@truncate:2064:" [... Sigue ...]"}
2) And then, works... All entries are truncated at 2064 characters. But, is it possible that the ' [... Sigue ...]' part of this code would be a link to the whole entry? I want this because with your code or the one I've modified it's impossible to see the whole entry... It's always truncated.
Is this possible?
Thanks in advance.
Posted: Tue Dec 16, 2008 5:26 pm
by Don Chambers
Yup! Its possible. This time I actually looked at the translucency template, since that seems to be what you are using.
The template already provides a link to the extended entry if it exists:
Code: Select all
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
That code not only opens the entry in full detail mode complete with comment form, but it specifically points to the id "extended". This is fine when your entry actually contains extended body text.
If it doesn't, then that id will not exist.... so lets just make a similar condition that thinks you have truncated, and point just to the entry instead of the extended.
Code: Select all
{if $entry.body|count_characters > 2064 and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
That will show, in your language, a prompt for "continue reading ENTRY TITLE". I am not factoring in the possibility that both conditions could be true - you have extended entry body, AND the entry body was truncated because it does not look like you are creating entries with both scenarios.
I have visited your site - in all honesty, I think you should not be using truncation in the way you are doing, and instead should divide your entries between an entry body, and extended body. There will be no chance of truncating an entry in the middle of open <tags>, and you don't have to have this additional processing occurring to truncate, etc.
Posted: Tue Dec 16, 2008 6:06 pm
by 3nd3r
Thank you!
Maybe you're right... And this would be a possibility in near future...
But now I need this "hack" to make all entries in my web (already imported) to be truncated in this way.
And, in the future, the option would be to enter a "teaser" entry with less than 2048 characters... right?
So, the code will be like this?:
Code: Select all
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
{if $entry.body|count_characters > 2064 and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
Or just replace the first code you've posted by the second one?
Posted: Wed Dec 17, 2008 9:42 am
by 3nd3r
Well none of the two options works...
If I replace this
Code: Select all
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
with this
Code: Select all
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
{if $entry.body|count_characters > 2064 and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
Or if I replace the first code just by this
Code: Select all
{if $entry.body|count_characters > 2064 and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
the results are that the "split" link is showed at the end of the entry, but also the whole entry... I mean, no split is made.
I've disabled this and uploaded original entries.tpl
Posted: Wed Dec 17, 2008 3:41 pm
by Don Chambers
You lost me a little ....
The stuff we did first provided your truncating... you want to leave that in tact.
The most ideal would be to combine the conditions so only one of the links will ever appear - if both conditions are met (ie, entry was truncated AND you have extended entry body), you would get the link twice.
To prevent that, try this:
Code: Select all
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{elseif $entry.body|count_characters > 2064 and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
That should replace the lines that currently do this:
Code: Select all
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br />
{/if}
Posted: Wed Dec 17, 2008 4:31 pm
by 3nd3r
Ok. Sorry if I'm annoying you... That's not my intention. Maybe my english isn't as good as I desire
I'll put the code in entries.tpl and you can see the result:
http://www.pajareo.com
The long entries (>2064) with no extended body part, have now a 'split link', but the entry are showed without truncating...
Thank you for your time