List & Detail - linking to an external file

3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 28, 2008   (RSS)

By rsekaly - September 27, 2008

I have a site which has a multi-record viewer. Two of the records are normal (title, summary, content). However, one of the records is a link to a pdf file (hyperlink in content field to pdf). As you can guess, this is very ugly, as you have to go from the list (title, summary) to the detail (title, content) page, then select the hyperlink.

Is there a cleaner way of doing the same thing?

Thanx........ ragi
--
Ragi Sekaly

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [rsekaly] List & Detail - linking to an external file

By MisterJim - September 28, 2008

One way would be to create a new field in your section to handle the external file link rather than putting it in the content section. Then, in your list page, use a conditional statement to determine exactly which field from your section is going to be used as the link.

Example:

Add a textfield to your section. Title it, for example, external_link. Now, in the record where you want to link to a pdf rather than move to a detail page, instead of placing any content in the content field, place the link url into the external_link field. Then save it.

In your list page code, right after the line <?php foreach ($xxxxxRecords as $record): ?>, add the following code:

<?php if ( !empty($record['external_link']) ) {
$new_link = $record['external_link'];
} else {
$new_link = $record['_link'];
} ?>


Then, where your code declares the url that should be used as the link, change:

<a href="<?php echo $record['_link'] ?>">

to:

<a href="<?php echo $new_link ?>">

Then, when you browse to your list page, the code will check to see if the new external_link field has something in it. If it does, then it will now use what's in that field for the link.

Hope this helps somewhat.

Jim
WebCamp One, LLC



Websites That Work

Re: [Mr Jim] List & Detail - linking to an external file

By rsekaly - September 28, 2008

That's great!

Thanx a lot Jim, it worked perfectly.
--
Ragi Sekaly

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke