If URL IS ENTERED - use as link

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 22, 2014   (RSS)

By csdesign - January 21, 2014

Hello! 

I have this code that's linking a stallion's name to it's page created in cmsb. and that works perfectly. 

<a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a>

However, there are hundreds of stallions that need their full bio (photos, lineage, etc)  to be added and we can't get them all done right away but they all  have an html page from the previous website which will be kept running in tandem with this one. 

I created a "stallion_url" field and what I would like to happen is that if there is an entry in the "stallion_url" text field then it will replace the '_link' in the code above. 

I tried this code below and it worked - except it still displays the cmsb generated '_link' after the 'stallion_url' (shown in bold). 
http://www.superiorequinesires.com/stallions/ludwig_von_bayern.shtmlstallion.php?Ludwig-von-Bayern-47

<a href="<?php if ($record['stallion_url'] ) : ?><?php echo $record['stallion_url'] ?><?PHP endif ?><?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a>

I added the code above to 3 breeds for testing: Bavarian, Bayern & Belgian.  Ludwig Von Bayern under Bayern is my Test - linking to his old page. 
http://www.superiorequinesires.com/stallion-list6breeds.php

Can you help  me with that please?  Thanks!!!! Tina

By Damon - January 22, 2014

Hi Tina,

Try this:

<?php if($record['stallion_url']) : ?>
    <a href="<?php echo $record['stallion_url']; ?>"><?php echo htmlencode($record['title']); ?></a>
<?php else : ?>
    <a href="<?php echo $record['_link']; ?>"><?php echo htmlencode($record['title']); ?></a>
<?php endif; ?>

Let me know if this works for you.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/