Either PDF or PHP page

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 31, 2011   (RSS)

By degreesnorth - March 30, 2011

Hi

I was wondering whether there is a way to choose whether the listing link goes to a PHP page or whether it can also go to a PDF? Here's the scenario. We have a number of reviews, sometimes they will be in text where we can load them on the site as php content (ie, text fields). Yet other times, they will be available as pdfs only and it's too difficult to reproduce all (especially if it's a newspaper clipping).

1. We have a reviewslist.php page which will always have a blurb intro with regards to what the review is, ie, http://www.audiomarketing.com.au/reviewslist.php

2. This currently goes to http://www.audiomarketing.com.au/reviewsdetail.php (for example) which is text based. However, when there is no text available, and only a pdf, is there code which can say, "select whether the detail page should go to text or pdf?" OR "if there's text, then display text, and IF there is no text, then display the pdf?

Or is that asking too much? I need to automate this as much as possible.

Thanks

Re: [degreesnorth] Either PDF or PHP page

By Toledoh - March 31, 2011

I normally have a field called "link type" that is a radio button with options as "internal", "external", "file".

Then I do an few if statments;
<?php if ($record['link_type'] == 'internal'): ?> ...your code...
<?php elseif ($record['link_type'] == 'external'): ?> ...your code...
<?php elseif ($record['link_type'] == 'file'): ?> ...your code...
<?php endif ?>
<?php endforeach; ?>

Cheers,

Tim (toledoh.com.au)

Re: [degreesnorth] Either PDF or PHP page

By Toledoh - March 31, 2011

Try this;
<?php if ($record['link_type'] == 'internal'): ?>
<a href="<?php echo $record['link_field'] ?>">Link within site as a text field</a>
<?php elseif ($record['link_type'] == 'external'): ?>
<a href="<?php echo $record['link_field'] ?>" target="_blank">Link outside of site as a text field</a>
<?php elseif ($record['link_type'] == 'details'): ?>
<a href="<?php echo $record['_link'] ?>">This links to your details page</a>
<?php elseif ($record['link_type'] == 'file'): ?>
<?php foreach ($record['file'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br />
<?php endif ?>
<?php endif ?>
<?php endforeach; ?>


Hope it helps!
Cheers,

Tim (toledoh.com.au)

Re: [degreesnorth] Either PDF or PHP page

By gkornbluth - March 31, 2011

Hi Carole,

If you're trying to differentiate between different file extensions and automatically publish the correct code for each, you can also try this kind of approach, excerpted from one of the recipes in my CMSB Cookbook http://www.thecmsbcookbook.com :
<?php foreach ($your_tableRecords as $record): ?> <?php foreach ($record['your_upload_field'] as $upload): ?>

<?php if ($upload['extension'] == 'pdf'): ?>

The pdf download code

<?php endforeach ?>
<?php else: ?>

Link to your detail page

<?php endif ?>
<?php endforeach ?>


Or, you could just test for the existence an upload in the pdf upload field. Something like:

<?PHP if ($your_field_nameRecord['uploads']): ?>

download link...

<?php else: ?>

Link to your detail page

<?php endif ?>


You'll have to play a bit with the exact code required, but I hope that gives you some ideas.

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