By roleychiu on
I may be shortsighted to suggest this, but why can we just take the string content of a textfield we create as the body content and then use basic PHP string manipulation within contemplate to save the first 50.. 100 or 121 characters to a variable and then output that in the contemplate of our teaser? That way we can control the characters that are spit out per content type by using the same code in other contemplates.
Would this work?
Comments
well my hunch was right.
well my hunch was right. Here's the code that you can put into your contemplate to customize any length of teaser you wish.
Hope this helps some people out
Source: http://www.totallyphp.co.uk/code/shorten_a_text_string.htm
edit: the above code works
edit: the above code works if there's only 1 node on the page. For multiple nodes, you need to put the function declaration in your template.php file so the function is globally accessible and not declared multiple times in the same page.
(for multiple nodes) I have
(for multiple nodes)
I have put this in my template.php
And in the node-nodetype.php I am calling this:
<?php print ShortenText($text); ?>Nothing appears except the "...".
-----------------------------
Subir Ghosh
www.subirghosh.in
FIXED
Template.php code remains the same.
I am using this in the node.tpl
<?php $text=$node->content['body']['#value']; print ShortenText($text); ?>-----------------------------
Subir Ghosh
www.subirghosh.in
What should one do if one
What should one do if one wants to have two types of such teasers?
Once the character limit is set in the template.php file, it becomes applicable throughout the site.
-----------------------------
Subir Ghosh
www.subirghosh.in
Do you want different length
Do you want different length teasers for different content types?
Try http://drupal.org/project/teaserbytype
(blowing own trumpet... ;)
lol why didn't I find your
lol why didn't I find your module sooner? So your module allows us to set any teaser length? even < 200? Does it truncate by char or does it retain the full word like in the code I posted?
It just gives the same
It just gives the same possible lengths as core does. And it truncates in the same way as core -- uses the same function.
I wish it came with lower numbers (or custom).
I really don't want to hack away.
Hmmm the number of people who
Hmmm the number of people who want this is growing -- http://drupal.org/node/306141
I might have to bow to demands and implement something. Will ponder.