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

Hello all I hope you can help with my problem.

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

Hi Chris,

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.
All the best,
Chris

Re: [chris] news content or pdf

By Chris_t - October 6, 2009

Thank you that did the trick. One issue that I found was when you clicked on the article to the details page the listing of all the news items went away and all that was left was the one related to the details page. Is there a way I can have both a list view and details view showing at the same time?
http://www.chs-mo.org/news.php

Thank you
Chris

Re: [Chris_t] news content or pdf

By Chris - October 6, 2009

Hi Chris,

Can you please post the PHP source code for that page?
All the best,
Chris

Re: [chris] news content or pdf

By Chris_t - October 6, 2009

For the news page I have up in the header

<?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

Hi Chris,

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.
All the best,
Chris

Re: [chris] news content or pdf

By Chris_t - October 6, 2009

Thank you very much that worked

Re: [Chris_t] news content or pdf

By Chris_t - October 7, 2009

Alright I have a follow up to that questions. The client wants it so when you go to the news page the current article is open to the left of the list. How do I script that so it skips the ones that are only pdfs and show the most recent one they wrote using the content box.

http://www.chs-mo.org/proof/news.php

Thank you again for all your help

Re: [chris] news content or pdf

By Chris_t - October 9, 2009

Ok that did not work but I think we are close.

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