How can I append cutText function with dot leaders?
7 posts by 3 authors in: Forums > CMS Builder
Last Post: January 5, 2010 (RSS)
By Deborah - January 2, 2010
<p>WYSISYG content blah, blah, blah ... <a href="#">more info</a></p>
Is there a modification I can do to the following existing code to accomplish this?
My code is as follows:
<head>
<?php function cutText($string, $setlength) {
$length = $setlength;
if($length<strlen($string)){
while (($string{$length} != " ") AND ($length > 0)) {
$length--;}
if ($length == 0) return substr($string, 0, $setlength);
else return substr($string, 0, $length);}
else return $string; }
?
<body>
<?php echo cutText($record['content'], 100); ?>
Thanks in advance for any help.
Deborah
Re: [Deborah] How can I append cutText function with dot leaders?
The approach to link to the complete article could be something as simple as
<a href="<?php echo $record['_link']; ?>... Read More</a>
There are also some ideas in the posts returned by forum searches for the complete phrases read more and word count.
Good luck with this
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] How can I append cutText function with dot leaders?
By Deborah - January 3, 2010
Thanks for you post. Your suggestion works fine when the field is a textfield or textbox. However, a WYSIWYG field automatically ends with a closing paragraph tag, so there's no way I know of to append content *before* that closing tag, which is what I'd like to do.
I'm thinking that it would be necessary to modify the cutText function, but I'm sadly not a PHP whiz.
Thanks again for your help.
Deborah
Re: [Deborah] How can I append cutText function with dot leaders?
Have a look at:
http://www.interactivetools.com/forum/gforum.cgi?post=63416#63416
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] How can I append cutText function with dot leaders?
By Deborah - January 4, 2010 - edited: January 7, 2010
This WYSYWIG field also has a cutText function, and I'm having difficulting getting that to work with the preg_replace.
It actually does work perfectly for ONE of the field's categories, but not for the other two.
Here's the tag I created:
<?php echo cutText($record['content']= preg_replace("|</p>\s*$|i", "...</p>", $record['content'] ), 90); ?>
Everything works for the "Friends" category, but not the other two. It doesn't matter in what order I place the three categories, "Friends" is the only one that displays correctly. For the other two, the text is trimmed via cutText, but the dots and closing </p> aren't added.
[ link removed ]
If I remove the cutText function, the preg_replace works on all three:
[ link removed ]
I can't understand what could be causing these differences. It seems that if my tag was incorrect, then it would affect display of all three categories.
I'm hoping someone at IT can help out? [unimpressed]
Deborah
Re: [Deborah] How can I append cutText function with dot leaders?
By Chris - January 5, 2010
I think the problem is that the cutText() function is (sometimes) stripping off the </p>. With no </p>, the preg_replace() can't find the right place to add the ...
For consistency, I'd recommend stripping the </p> off first, then calling cutText(), then adding your read more link, and finally replacing the </p>:
<?php
$html = preg_replace("|</p>\s*$|i", "", $record['content'] );
$html = cutText($html, 90);
$html = $html . "...</p>";
echo $html;
?>
Does that do what you want? Please let me know if you have any questions.
Chris
Re: [chris] How can I append cutText function with dot leaders?
By Deborah - January 5, 2010
The suggested code works great!
Thanks so much for your help.
Deborah