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 Jason - May 27, 2010

Hi,

For your first question, you just need to replace what appears between the <a></a> tags. Right now, you have this:
<a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

You need to replace it with this:
<a href="<?php echo $record['_link'] ?>">*YOUR TEXT HERE*</a><br/>

You just need to replace "*YOUR TEXT HERE*" with whatever text you want displayed as a link.

We need to make a few more changes to newsDetail.php.

First, we need to restrict the number of records being returned to only return 1. Replace your current getRecords statement with this:


// load records
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => whereRecordNumberInUrl(1),
'limit' => 1,
));


This will only return one record. Now we need to select that record. Put this code right below:

$newsRecord=$newsRecords[0]; //select the first record.


Last thing we need to do is change the code where we're outputting our content. Replace all the code in "STEP 2" with this:


<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<?php echo date("D, M jS, Y g:i:s a", strtotime($newsRecord['date'])) ?><br/>
<!-- For date formatting codes see: http://www.php.net/date -->
<span class="headline"><?php echo $newsRecord['title'] ?></span><br/>
<?php echo $newsRecord['content'] ?><br/>
<hr/>

<?php if (!$newsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->&nbsp;</p></td>


Give this a try and let me know if you run into any issues.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

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!