news content or pdf
13 posts by 2 authors in: Forums > CMS Builder
Last Post: October 13, 2009 (RSS)
By Chris_t - October 6, 2009
A client wants there news page to have a list of all the stories on the side linking to the details of the story. That is easy the problem comes when all they do is link to a pdf in the uploads area. Is there an if else command that would have it link to the details page if they write in the content WYSIWYG area if not then link to the PDF?
Thank you for your time.
Chris
Re: [Chris_t] news content or pdf
By Chris - October 6, 2009
Certainly. You'd want to do something like this:
<?php foreach ($newsRecords as $record): ?>
<?php if (!$record['content'] && !empty($record['upload'])): ?>
<a href="<?php echo $record['upload'][0]['urlPath'] ?>">
<?php else: ?>
<a href="<?php echo $record['_link'] ?>">
<?php endif ?>
<?php echo $record['title'] ?>
</a>
<br />
<?php endforeach; ?>
Note that you'll need to change the name of your record variable and its fields to match your own (all shown in red above.) Also, I changed the condition slightly: the link will be to the first uploaded file in the 'upload' field, but only if there is at least one file uploaded to that field and the 'content' field is blank.
I hope this helps! Please let me know if you have any questions.
Chris
Re: [chris] news content or pdf
By Chris_t - October 6, 2009
http://www.chs-mo.org/news.php
Thank you
Chris
Re: [Chris_t] news content or pdf
By Chris - October 6, 2009
Can you please post the PHP source code for that page?
Chris
Re: [chris] news content or pdf
By Chris_t - October 6, 2009
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsRecords, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
));
?>
For the links to the news in the body of the page<?php foreach ($in_the_newsRecords as $record): ?>
<?php if (!$record['content'] && !empty($record['pdf'])): ?>
<a href="<?php echo $record['pdf'][0]['urlPath'] ?>">
<?php else: ?>
<a href="<?php echo $record['_link'] ?>">
<?php endif ?>
<br /><?php echo $record['title'] ?>
</a>
<br />
<?php endforeach; ?>
<?php if (!$in_the_newsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
Is in the header for the news detail page<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsRecords, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
));
?>
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsRecords, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$in_the_newsRecord = @$in_the_newsRecords[0]; // get first record
// show error message if no matching record is found
if (!$in_the_newsRecord) {
print "Record not found!";
exit;
}
?>
displays the content field for the news <h1><?php echo $in_the_newsRecord['title'] ?></h1><br/>
<?php echo $in_the_newsRecord['content'] ?><br/>
<?php if (!$in_the_newsRecord): ?>
No record found!<br/><br/>
<?php endif ?>
Is the list<?php foreach ($in_the_newsRecords as $record): ?>
<?php if (!$record['content'] && !empty($record['pdf'])): ?>
<a href="<?php echo $record['pdf'][0]['urlPath'] ?>">
<?php else: ?>
<a href="<?php echo $record['_link'] ?>">
<?php endif ?>
<br /><?php echo $record['title'] ?>
</a>
<br />
<?php endforeach; ?>
<?php if (!$in_the_newsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
Hope that helps
Re: [Chris_t] news content or pdf
By Chris - October 6, 2009 - edited: October 6, 2009
I think the problem is here:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsRecords, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
));
?>
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsRecords, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$in_the_newsRecord = @$in_the_newsRecords[0]; // get first record
// show error message if no matching record is found
if (!$in_the_newsRecord) {
print "Record not found!";
exit;
}
?>
Specifically, you're overwriting the $in_the_newsRecords variable. Initially you load in all the records (in red), then you load in the single record "whereRecordNumberInUrl" (in blue). I would suggest renaming the blue text above to $in_the_newsSelectedRecord.
I hope this helps. Please let me know if you have any questions or comments.
Chris
Re: [Chris_t] news content or pdf
By Chris_t - October 7, 2009
http://www.chs-mo.org/proof/news.php
Thank you again for all your help
Re: [Chris_t] news content or pdf
By Chris - October 8, 2009 - edited: October 8, 2009
You can skip over records with a the "continue" statement. You can stop with the "break" statement. Here's an example which would skip entries with a blank "content" field, then stop after the first one it doesn't skip.
<?php foreach ($in_the_newsRecords as $record): ?>
<?php if (!$record['content']) { continue; } ?>
... display record ...
<?php break; ?>
<?php endforeach ?>
I hope this helps. Please let me know if you have any questions.
Chris
Re: [chris] news content or pdf
By Chris_t - October 9, 2009
This is in the heading to display the new articles on the right hand side
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsRecords, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
));
?>
Here is the header code for displaying the details of the article
<?php
require_once "/home/chsm00/public_html/cmsAdmin/lib/viewer_functions.php";
list($in_the_newsSelectedRecord, $in_the_newsMetaData) = getRecords(array(
'tableName' => 'in_the_news',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$in_the_newsRecord = @$in_the_newsSelectedRecord[0]; // get first record
// show error message if no matching record is found
if (!$in_the_newsRecord) {
print "Record not found!";
exit;
}
?>
For the list of articles I have the code you provided before works great by the way.
<?php foreach ($in_the_newsRecords as $record): ?>
<?php if (!$record['content'] && !empty($record['pdf'])): ?>
<a href="<?php echo $record['pdf'][0]['urlPath'] ?>">
<?php else: ?>
<a href="<?php echo $record['_link'] ?>">
<?php endif ?>
<br /><?php echo $record['title'] ?>
</a>
<br />
<?php endforeach; ?>
<?php if (!$in_the_newsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
Then to display the details of the most current content written article on the right I have
<?php foreach ($in_the_newsRecords as $record): ?>
<?php if (!$record['content']) { continue; } ?>
<?php break; ?>
<?php endforeach ?>>
http://www.chs-mo.org/proof/news.php
Thank you for your time