Hyperlinking Menu Items in CMS Builder

8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 12, 2008   (RSS)

By Laura - September 10, 2008

I have set up CMS builder for a new website I am working on with great success. I really enjoy this product! I have set up the Section Editor using the Category option. That being said, I have a few menu items that need to be hyperlinked to other websites from the navigation menu that is created with CMS Builder verses having a page and linking off of the page. I know this can be achieved with a simple if/else statement. Basically stating that if there is no content link to this site for the particular page however I need assistance in the creation and implementation of this script. As I do not fully understand how everything is working in CMS Builder I would appreciate some help in creating this script and determining where to place it within the code to properly work.

Re: [Laura] Hyperlinking Menu Items in CMS Builder

By Dave - September 10, 2008

Hi Laura,

Here's some steps:

First, try adding a field for "externalLink".

Next, try getting it to display under the existing menu links. The code will look something like this (use the variable names you have in the page already):
<?php echo $yourRecord['externalLink'] ?>

Next, add an if statement so if there is an external link that shows, but if not it shows the regular menu link:

<?php if ($yourRecord['externalLink']): ?>
<?php echo $yourRecord['externalLink'] ?>
<?php else: ?>
... old menu link here ...
<?php endif ?>


Give that a try and let me know how far you get or if you need any more help. :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hyperlinking Menu Items in CMS Builder

By Laura - September 11, 2008

Thanks Dave! That makes sense. Just to confirm that I have the placement of the scripts correct, do you mind reviewing my code below?

(The field added to the database is named externalLink as in your example above)



Original Code:
<!-- category menu -->

<?php foreach ($categoryRecords as $categoryRecord): ?>

<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>

<?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>
<br/>
<?php endforeach; ?>
<!-- /category menu -->

Updated Code:

<!-- category menu -->

<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>

<?php if ($categoryRecord['externalLink']): ?>
<?php echo $categoryRecord['externalLink'] ?>
<?php else: ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>
<?php endif ?>
<?php endforeach; ?>

<br/>

<!-- /category menu -->


Thanks!

Re: [Dave] Hyperlinking Menu Items in CMS Builder

By Laura - September 11, 2008

[font "Calibri"]Dave,

[font "Calibri"]The functionality works in that the field with the external hyperlink is added to the menu structure and looks exactly like the other menu items. However, the nesting does not work. I believe it has to do with the depth. In short the menu is not displaying the subcategory and sub-subcategory hierarchy as before. The menu is all one consistent column. When a menu item which has a subcategory is clicked, the subcategory displays directly under the main category. Like so:

[font "Calibri"]

[font "Calibri"]Parent Category

[font "Calibri"]Subcategory

[font "Calibri"]Sub-Subcategory

[font "Calibri"]

[font "Calibri"]Before it displayed as so:

[font "Calibri"]Parent Category

[font "Calibri"]-Subcategory

[font "Calibri"]--Sub-Subcategory

[font "Calibri"]

[font "Calibri"]Thoughts?

[font "Calibri"]Laura

Re: [Laura] Hyperlinking Menu Items in CMS Builder

By Dave - September 11, 2008

Hi Laura,

That's strange, the code looks perfect to me.

Can you send me CMS and FTP login info (to dave@interactivetools.com, don't post login details to forum) and I'll take a look for you?

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Laura] Hyperlinking Menu Items in CMS Builder

By Dave - September 12, 2008

Hi Laura,

I made the following changes (in red):

<!-- category menu -->
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>

<?php if ($categoryRecord['externalLink']): ?><br>

<a href="<?php echo $categoryRecord['externalLink'] ?>"><?php echo $categoryRecord['name'] ?></a>

<?php else: ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>
<?php endif ?>
<?php endforeach; ?>

<br/>
<!-- /category menu -->


Let me know if that work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hyperlinking Menu Items in CMS Builder

By Laura - September 12, 2008

Thanks Dave! This works perfectly!