Multiple record listing

4 posts by 3 authors in: Forums > CMS Builder
Last Post: May 18, 2010   (RSS)

By Oakweb - May 16, 2010

Hi

I have just purchased my first copy of CMS Builder having used Realty Manager to build Property sites before. I have a couple of questions. I have done a news page which lists news items down the page with a limit of 10 per page and that is fine. I also have a panel on each page which will list the latest 5 news headlines. This is also on the news page as it is integral to the site. How do I set a separate limit of 5 records in the headlines panel whilst retaining 10 news items per page in the main news listing.

Also are there any instructions anywhere for getting featured listings working as I would like to dot a few featured properties around the site.

Hope this makes sense.
[/#000000]

Re: [Oakweb] Multiple record listing

By gkornbluth - May 16, 2010

Hi Oakweb,

Based on one of the recipes in my CMSB Cookbook http://www.thecmsbcookbook.com, one possible approach is that you can have separate list records calls in the body of your page that set different parameters for the separate lists of articles.

So the code for the headlines could be something like:

<?php

list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '5',
));
?>
<table width="100" Align="left" border="0" cellpadding="5">
<?PHP foreach ($newsRecords as $record): ?>
<tr>
<td><?PHP echo $record['_link'] ?>"><?PHP echo $record['headline'] ?>
</td>
</tr>
<?PHP endforeach; ?>
</table>


And the code for the item listing could be something like

<?php

list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '10',
));
?>
<table width="100" Align="left" border="0" cellpadding="5">
<?PHP foreach ($newsRecords as $record): ?>
<tr>
<td><?PHP echo $record['_link'] ?>"><?PHP echo $record['content'] ?>
</td>
</tr>
<?PHP endforeach; ?>
</table>


If you want to limit the number of words in the” item” listings, here’s a recipe from the Cookbook which addresses that concept.

LIMITING THE NUMBER OF WORDS SHOWN IN A PAGE
If you use the character limiting function that’s exactly what you’ll get, and words can be cut off. But if you want to limit the word count, Dave Edis from Interactive Tools shares his usual uncanny wisdom:

Put this code at the top of your page, or before you want to invoke the word limiting function:

<?PHP
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);

return $output;
}
?>


Then put this code inside the foreach loop where you want the words limited (to 5 words):

<?PHP echo maxWords($record['content'], 5);
?>

If you want to add ...more and a link, use something like this:

<?PHP echo maxWords($record['content'], 5);
?>...<a href="<?php echo $record['_link']; ?>”>Read More</a>


If you’re using a WYSIWYG Editor and are losing some formatting when using the MaxWord function, Jason Sauchuk of Interactive Tools suggests using this version of the function instead:

<?PHP
function maxWords($textOrHtml, $maxWords) {
$text=str_replace("<p>","*P*",$textOrHtml);
$text= str_replace("</p>","*/P*",$text);
$text = strip_tags($text);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
$output=str_replace("*P*","<p>",$output);
$output=str_replace("*/P*","</p>",$output);
$output.="</p>";

return $output;
}
?>


Hope that helps to get you started.

Best,

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: [ross] Multiple record listing

By Oakweb - May 18, 2010

Many thanks for your help - all working well