getting a single news item to show.

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

By (Deleted User) - May 27, 2010 - edited: June 7, 2010

hi. I have set up a multi list page (labeled news.php) and set up a page detail as newsDetail.php -- I'm having a problem with two things.

1) on the news.php page.. any way to change the link i.e. newsDetail.php?news-headline-to-come-here-4 to something else like... click here for more info?

2) on the detail page --- any way to show one news item instead of all of them????

THANKS! I'm loving this tool!

-CF

Re: [cfdesign] getting a single news item to show.

By gkornbluth - May 27, 2010

Hi cfdesign,

If I understand what you're asking, both are possible, and easy.

The showing only the first news item is as easy as inserting a <?PHP break ?> before your <?PHP endforeach ?> which will tell the loop to stop after it runs through once.

Changing the link to ...click for more... can be accomplished in a few ways.

Here's an excerpt from my CMSB Cookbook thecmsbcookbook.com that describes one approach using a word count to determine when the "click for more" is displayed.

In the head of your page insert the following code: (straight out of the code generator)
<?php

require_once "/your_path_to/cmsAdmin/lib/viewer_functions.php";

list($your_tableRecords, $your_tableMetaData) = getRecords(array(
'tableName' => 'your_table',

));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">


In the body of your page, before you display your information, put the following code to set up the maxwords 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, where you want to display your articles and pictures, use something like this:

strupper forces the title to be displayed in CAPS, the number in the <?PHP echo maxWords($record['full_article'], 40); line sets the number of words to display before the ... (read more).

<?php foreach ($your_tableRecords as $record): ?>
<?php foreach ($record['your_image'] as $upload): ?>
<a href="http://www.your_site.com/your_detail_page.php?<?php echo $record['num'] ?>"><br /><br /><img border="0" src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" align="center" /></a>
<?php endforeach ?>
</td>
<td align="left" valign="top"><div><a href="http://www.your_site.com/your_detail_page.php?<?php echo $record['num'] ?>"><?php $event_title = ($record['title']); ?><?php echo strtoupper($title); ?></a></div>
<br />
<?PHP echo maxWords($record['full_article'], 40);
?>...<a href="http://www.your_site.com/your_detail_page.php<?php echo $record['num'] ?>">(Read More)</a>
<?php endforeach; ?>
</td>
</tr>
</table>


Styling is of course up to you.
Hope that gives you some ideas.

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: [Jason] getting a single news item to show.

By (Deleted User) - May 27, 2010

PERFECT! Thanks That did the trick!!!! I appreciate your help!