Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
news content or pdf

 

 


Chris_t
Novice

Oct 6, 2009, 9:25 AM

Post #1 of 13 (1790 views)
Shortcut
news content or pdf Can't Post

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


Chris
Staff


Oct 6, 2009, 10:26 AM

Post #2 of 13 (1788 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

Hi Chris,

Certainly. You'd want to do something like this:


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


Chris_t
Novice

Oct 6, 2009, 12:36 PM

Post #3 of 13 (1780 views)
Shortcut
Re: [chris] news content or pdf [In reply to] Can't Post

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


Chris
Staff


Oct 6, 2009, 12:56 PM

Post #4 of 13 (1776 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

Hi Chris,

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


Chris_t
Novice

Oct 6, 2009, 1:08 PM

Post #5 of 13 (1774 views)
Shortcut
Re: [chris] news content or pdf [In reply to] Can't Post

For the news page I have up in the header


Code
<?php header('Content-type: text/html; charset=utf-8'); ?> 
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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


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



Code
<?php header('Content-type: text/html; charset=utf-8'); ?> 
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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


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

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


Chris
Staff


Oct 6, 2009, 1:15 PM

Post #6 of 13 (1767 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

Hi Chris,

I think the problem is here:


Code
<?php header('Content-type: text/html; charset=utf-8'); ?>  
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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


(This post was edited by chris on Oct 6, 2009, 1:15 PM)


Chris_t
Novice

Oct 6, 2009, 1:21 PM

Post #7 of 13 (1762 views)
Shortcut
Re: [chris] news content or pdf [In reply to] Can't Post

Thank you very much that worked


Chris_t
Novice

Oct 7, 2009, 1:49 PM

Post #8 of 13 (1743 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

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


Chris
Staff


Oct 8, 2009, 3:46 PM

Post #9 of 13 (1731 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

Hi Chris,

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.


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


(This post was edited by chris on Oct 8, 2009, 3:47 PM)


Chris_t
Novice

Oct 9, 2009, 9:29 AM

Post #10 of 13 (1724 views)
Shortcut
Re: [chris] news content or pdf [In reply to] Can't Post

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


Code
<?php 
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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

Code
<?php 
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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.

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

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


Chris
Staff


Oct 11, 2009, 1:30 PM

Post #11 of 13 (1696 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

Hi Chris,

You'll need to replace "... display record ..." with the PHP code you use to display your records.

For example,


Code
<?php foreach ($in_the_newsRecords as $record): ?>  
<?php if (!$record['content']) { continue; } ?>

<h2><?php echo $record['title']; ?></h2>
<?php echo $record['content']; ?>


<?php break; ?>
<?php endforeach ?>


I hope this helps. Please let me know if you have any questions.
Chris


Chris_t
Novice

Oct 12, 2009, 7:10 AM

Post #12 of 13 (1685 views)
Shortcut
Re: [chris] news content or pdf [In reply to] Can't Post

Bingo that works thanks for the help


Chris
Staff


Oct 13, 2009, 11:03 AM

Post #13 of 13 (1649 views)
Shortcut
Re: [Chris_t] news content or pdf [In reply to] Can't Post

Glad to be of help! :)
Chris