link change based on field contents
5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 15, 2010 (RSS)
By Oakweb - November 13, 2010
So for the list page I currently have
<?php foreach ($adventure_and_sportRecords as $record): ?><div class="itemPreview">
<a href="<?php echo $record['_link'] ?>"><h1><?php echo $record['title'] ?></h1></a>
<?php echo $record['preview_description'] ?><a href="<?php echo $record['_link'] ?>"><strong>Find out more »</strong></a>
</div>
<?php endforeach ?>
This gives a few details of the organisation and then links to the detail page.
I have a field for the website address in the section editor - <?php echo $adventure_and_sportRecord['website'] ?>
So what I need to do is if the "website" field has a Url in it I need the "Find out more" link to go straight to that site and if the field is empty I need it to go to the detail page.
I have seen some bits about If statements on the forum, but can't work out if it is possible to utilize it here.
Any help would be much appreciated.
Re: [Oakweb] link change based on field contents
By zip222 - November 14, 2010
<?php foreach ($adventure_and_sportRecords as $record): ?>
<div class="itemPreview">
<?php if ($record['website']): ?>
<h1><a href="<?php echo $record['website'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['website'] ?>">Find out more »</a></strong>
<?php else ?>
<h1><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['_link'] ?>">Find out more »</a></strong>
<?php endif ?>
</div>
<?php endforeach ?>
Re: [zip222] link change based on field contents
By Oakweb - November 15, 2010
Unfortunately this has thrown up the error
Parse error: syntax error, unexpected ';', expecting ':' in /home/asksam/3P216Y7H/htdocs/adventure_and_sport.php on line 88
Line 88 refers to <?php else ?>
Re: [zip222] link change based on field contents
By Oakweb - November 15, 2010
Should have been
<?php foreach ($adventure_and_sportRecords as $record): ?>
<div class="itemPreview">
<?php if ($record['website']): ?>
<h1><a href="<?php echo $record['website'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['website'] ?>">Find out more »</a></strong>
<?php elseif ($record['_link']): ?>
<h1><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['_link'] ?>">Find out more »</a></strong>
<?php endif ?>
</div>
<?php endforeach ?>
It was the <?php elseif ($record['_link']): ?> bit.
Thanks for your help though as I wouldn't have got that far without your start.
Re: [Oakweb] link change based on field contents
By zip222 - November 15, 2010
<?php else: ?>