Redirect URL
5 posts by 2 authors in: Forums > CMS Builder
Last Post: December 16, 2014 (RSS)
By drewh01 - December 15, 2014
I have a redirect field called : redirect : that I would like to use in my code.
How can I do this?
Example:
<?php foreach ($festival_archive_2014Records as $record): ?>
<p><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['name']) ?></a></p>
<?php endforeach ?>
<?php if (!$festival_archive_2014Records): ?>
No records were found!<br/><br/>
<?php endif ?>
By claire - December 16, 2014
Hi there
I'm not sure I understand where you want the redirect code to be added here? Do you want it in place of the $record['_link']?
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By drewh01 - December 16, 2014 - edited: December 16, 2014
I would like to insert code to the above that when the 'redirect' field in the admin is filled in with a custom URL that it will override the _link value. Hope this makes sense.
Right now when I add this code, it duplicates any custom URL redirects that I have used. I guess I am needing to use a foreach or a if then statement somehow?
<?php if($record['redirect']):?>
<p><a href="<?php echo $record['redirect'] ?>"><?php echo htmlencode($record['name']) ?></a></p>
<?php endif; ?>
By claire - December 16, 2014
No no, just a plain if-else will do it here. Try this:
<?php foreach ($festival_archive_2014Records as $record): ?>
<?php if($record['redirect']):?>
<p><a href="<?php echo $record['redirect'] ?>"><?php echo htmlencode($record['name']) ?></a></p>
<?php else : ?>
<p><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['name']) ?></a></p>
<?php endif; ?>
<?php endforeach ?>
<?php if (!$festival_archive_2014Records): ?>
No records were found!<br/><br/>
<?php endif ?>
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By drewh01 - December 16, 2014
Ahhh...yes, that makes sense. Thanks for the help...i'm still learning!
:-)