Shortening entries only on main page
Shortening entries only on main page
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.
Thanks in advanced.
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.
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.
Sorry for bump this not-too-old post, but that's exactly what I want!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.
Can you tell me how could I make it?
Thanks in advance for your time!
Try not. Do, or do not. There is no try.
-
Don Chambers
- Regular
- Posts: 3657
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
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:
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:
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}Code: Select all
<div class="entry-content serendipity_entry_body">
{$entry.body|@strip_tags|@strip|@truncate:400:" ..."}=Don=
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:
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.
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 ...]"}Is this possible?
Thanks in advance.
Try not. Do, or do not. There is no try.
-
Don Chambers
- Regular
- Posts: 3657
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
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:
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.
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.
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}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}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.
=Don=
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?:
Or just replace the first code you've posted by the second one?
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}Try not. Do, or do not. There is no try.
Well none of the two options works...
If I replace this
with this
Or if I replace the first code just by this
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
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} 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}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}I've disabled this and uploaded original entries.tpl
Try not. Do, or do not. There is no try.
-
Don Chambers
- Regular
- Posts: 3657
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
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:
That should replace the lines that currently do this:
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}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}=Don=
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
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
Try not. Do, or do not. There is no try.