How to make single link change automatically based on filetype
7 posts by 3 authors in: Forums > CMS Builder
Last Post: January 14, 2009 (RSS)
By eriqcook - January 9, 2009 - edited: January 10, 2009
Please take a look at the folowing web page:
http://www.mtrip.org/v2/cmstest.php
In the 4th row of each entry (titled "File"), I want to be able to have a single link that changes automatically based on the type of file it is. In other words, if the entry is a basic article, I want the link to read "View Page", or if it's a file download (PDF, DOC, XLS, etc), the link would read "View/Download File" (instead of showing both "[url "http://www.interactivetools.com/forum/forum.cgi?url=http%3A%2F%2Fwww.interactivetools.com%2Fforum%2Fforum.cgi%3Furl%3Dhttp%253A%252F%252Fwww.mtrip.org%252Fv2%252Farticles%252FarticleDetail.php%253FLogo-Creative-Brief-2"]View Web Page[/#0066cc][/url]" AND "[url "http://www.interactivetools.com/forum/forum.cgi?url=http%3A%2F%2Fwww.interactivetools.com%2Fforum%2Fforum.cgi%3Furl%3Dhttp%253A%252F%252Fwww.mtrip.org%252Fv2%252FcmsAdmin%252Fuploads%252FLogoCreativeBrief.pdf"]View/Download[/#0066cc][/url]" at the same time). I don't like having to show both text links if only one works. Does that make sense?
I think what I want to do is something with an "IF" or "ELSE" statement, but I'm not sure how to code it. Can anyone here provide some example code to acheive the results I need? Here's the code I that's in place now:
<a href="<?php echo $record['_link'] ?>">View Web Page</a><br/>
<!-- STEP 2a: Display Uploads for field 'file' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<?php foreach ($record['file'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">View/Download<br />
</a>
<?php endif ?>
<?php endforeach ?>
I really don't care about the the thumbnail references (since I'm not showing thumbnails) but tried removing them and screwed up everything. And I'm not sure how to code if/else statements to generate the results I want. I need help. Need to launch this site by Sunday (tomorrow).
Greatly appreciated.
Re: [eriqcook] How to make single link change automatically based on filetype
By ross - January 12, 2009
Thanks for posting!
I think what I'll do is just go over the code briefly so we can both be sure I am on the right track here :).
You are definitely off to a good start with the if/else approach, so that's going to work.
First off, the way I see it, each article will have the option of linking to a full article page or right to a file download.
The idea behind those if/elses is going to be something like this:
if upload fields is not blank (which means you've uploaded a file), display a link to download the file.
if the upload field is blank (you have not uploaded a file), display a link to the full article.
Does that sound about right? Let me know and I'll go over the code in more detail.
Thanks!
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Re: [ross] How to make single link change automatically based on filetype
By eriqcook - January 12, 2009
Re: [eriqcook] How to make single link change automatically based on filetype
By Dave - January 13, 2009
Try something like this:
<?php if ($upload['extension'] == 'gif'): ?>
<a href="...">View Image</a>
<?php elseif ($upload['extension'] == 'pdf'): ?>
<a href="...">View PDF</a>
<?php else: ?>
<a href="...">View All other files</a>
<?php endif ?>
Let me know if that works for you or if you run into any problems.
interactivetools.com
Re: [Dave] How to make single link change automatically based on filetype
By eriqcook - January 13, 2009
Hi Eriq,
Try something like this:
<?php if ($upload['extension'] == 'gif'): ?>
<a href="...">View Image</a>
<?php elseif ($upload['extension'] == 'pdf'): ?>
<a href="...">View PDF</a>
<?php else: ?>
<a href="...">View All other files</a>
<?php endif ?>
Let me know if that works for you or if you run into any problems.
Re: [eriqcook] How to make single link change automatically based on filetype
By eriqcook - January 13, 2009
Anyway, what I said was that I changed the code to match to the correct file type, but if you look at the following page:
http://www.mtrip.org/v2/cmstest.php
You'll see it only shows "View Page" (for "non file upload" articles). It's supposed to say "View PDF" if the filetype is a PDF, or "View Page" if there's no file uploaded and just a standard article page.
If you click on the "View Page" link however, it loads the article detail page and displays the file at the very bottom (IF the file exist). Not exactly how I wanted it to work though.
It may have something to do with how I have everything setup on the back side. I don't know. You may need to look at how I have things setup internally to see what's wrong here.
Thank you for your help...
Re: [eriqcook] How to make single link change automatically based on filetype
By Dave - January 14, 2009
Can you attach the cmstest.php file to this post or email me CMS and FTP login details to dave@interactivetools.com (email, don't post login details to the forum) so I can take a closer look at the code?
Thanks!
interactivetools.com