Is there a better way to link?
3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 28, 2013 (RSS)
By Toledoh - June 26, 2013
Hi Guys,
I've currently got a multi-section "Featured Items" which allows you to create items on the home page, give it a title, image, description, then link to another part of the site. The same function for "Side Items" and another for "Quick Links" etc.
In each of these section editors, I have the follow fields that allows the user to select where they want that record to link to;
separator: "Choose one of the following items"
pulldown-list: select from database / articles / num / title
pulldown-list: select from database / events / num / title
pulldown-list: select from database / pages / num / title
pulldown-list: select from database / report / num / title
I then use the following to link;
<?php if ($record['article']): ?><a href="articleDetails.php?num=<?php echo $record['article'] ?>" class="actionButton"><?php endif ?>
<?php if ($record['report']): ?><a href="reportDetail.php?num=<?php echo $record['report'] ?>" class="actionButton"><?php endif ?>
<?php if ($record['event']): ?><a href="eventDetails.php?num=<?php echo $record['event'] ?>" class="actionButton"><?php endif ?>
<?php if ($record['pages']): ?><a href="pages.php?num=<?php echo $record['pages'] ?>" class="actionButton"><?php endif ?>
Read More</a>
Is there a better way?
Tim (toledoh.com.au)
By Jason - June 27, 2013
Hi Tim,
Your process looks right. The only issue you would run into is if they selected values in more than 1 drop down, your code would produce multiple links. You can try this method that would eliminate that possibility:
<?php
$pageName = "";
$recordNum = coalesce($record['article'], $record['report'], $record['event'], $record['pages']);
if ($record['article']) {
$pageName = "articleDetails.php";
}
elseif($record['report']) {
$pageName = "reportDetails.php";
}
elseif($record['event']) {
$pageName = "eventDetails.php";
}
else {
$pageName = "pages.php";
}
?>
<a href = "<?php echo $pageName;?>?num=<?php echo $recordNum;?>" class = "actionButton">Read More</a>
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/