Hi Everyone,
In the phptemplate theme snippits, I found some code which trims the text at a set number of words. I am using this, in combination with a customized flexinode template file, in an effort to create a teaser for my flexinode content type.
This is the code in my template.php file:
<?php
function drupalicious_summarise($paragraph, $limit)
{
$textfield = strtok($paragraph, " ");
while($textfield)
{
$text .= " $textfield";
$words++;
if(($words >= $limit) && ((substr($textfield, -1) == "!")||(substr($textfield, -1) == ".")))
break;
$textfield = strtok(" ");
}
return ltrim($text);
}
?>
And this is part of the code I currently have in my node-flexinode-2.tpl.php file:
<?php if ($page == 0) {
$node->flexinode_3 = drupalicious_summarise($node->flexinode_3,150);?>
<div class="flexifield_three"> <?php print check_markup($node->flexinode_3, $node->flexinode_3_format, FALSE);?> </div>
<div class="continuereading"> <?php print l("-- Continue Reading This Entry --", "node/". $node->nid);?> </div>
<?php } ?>
The above works great, except that I need it to only show the "contine reading this entry" if there is more text then is shown as part of the teaser. So in other words, I only want to have the "continue reading this entry" link if there is more to read.
Please let me know your thoughts and if possible, please reply with the modified code.
Thanks very much,
Dan
Comments
You really shouldn't change
You really shouldn't change the contents of objects like this: $node->flexinode_3 = ...
I would guess the solution will be something like:
Thanks
That got me thinking along the right track. The above code didn't work because the a $maxlen of 150 represents the number of words, not characters... so if (strlen($content) > $maxlen) was almost always returning a true.
I used the code below:
Try as I Might, I can't get drupalicious_summarise to work
I copied the druplalicious_summarise code above into my phptemplate.php file. I added this code to my node-flexinode-n.tpl.php file:
And yet, my teaser continues to print the full text of the field. It is a textarea field. What the heck am I doing wrong? Here is the drupalicous_summarise code exactly as it appears in my phptemplate.php file:
Thanks!