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

I am using a cutText function found on this forum to limit the number of characters in a WYSIWYG field. Because the WYSIWYG content automatically generates a closing </p> tag, I am unable to append a dot leader and "more" link such as this at the end of the snipped text:
<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?

Hi Deborah,

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
The first CMS Builder reference book is now available on-line!







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

Hi, Jerry.

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?

Life sure does get complex doesn't it.

Have a look at:

http://www.interactivetools.com/forum/gforum.cgi?post=63416#63416

Jerry
The first CMS Builder reference book is now available on-line!







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

Jerry, the post you found got me definitely headed in the right direction. Thank you!

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: [chris] How can I append cutText function with dot leaders?

By Deborah - January 5, 2010

Hi, Chris.

The suggested code works great!

Thanks so much for your help.

Deborah