Amount of words in the list view. Noob needs help!
2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 23, 2008 (RSS)
By ventana - January 23, 2008
Firstly it looks like CMS builder is just the ticket and I'm sure if I knew some (any!) php i'd be flying along..... but I don't. [blush] So...
I've got the list and page concept down and working but have no idea how I restrict the list view to only the first 25 words (for example). What do I need to do?
I've got the list and page concept down and working but have no idea how I restrict the list view to only the first 25 words (for example). What do I need to do?
Re: [ventana] Amount of words in the list view. Noob needs help!
By Dave - January 23, 2008
Hi Ventana, welcome aboard!
There's two ways to do that. The simplest is just to have a 'summary' field. This lets the user have complete control over what's in the summary. And you can set a max character limit on the field as well.
Next, the PHP code version, as requested:
Instead of this:
Try this:
That splits up the content on spaces and then output the first three words (or however many you specify).
Hope that helps! :)
There's two ways to do that. The simplest is just to have a 'summary' field. This lets the user have complete control over what's in the summary. And you can set a max character limit on the field as well.
Next, the PHP code version, as requested:
Instead of this:
<?php echo $record['content'] ?>
Try this:
<?php
$maxWords = 3;
$words = explode(" ", $record['content']);
$words = array_slice($words, 0, $maxWords);
$summary = join(" ", $words);
print $summary;
?>
That splits up the content on spaces and then output the first three words (or however many you specify).
Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com