Active menu, and submenu

9 posts by 3 authors in: Forums > CMS Builder
Last Post: January 30, 2009   (RSS)

How could I make it so that when I have.. let's say 2-3 level menu and have chosen from the website a link from second menu level.

I would like the first level link to be active (eg bold) as well as the second level link from the selected ones.

Thank you,
Martin

Re: [solar_sys] Active menu, and submenu

By Kenny - January 29, 2009

Martin,

Are you talking about the program itself or menus that you are creating on your website? If you are talking about your website, you will need to pick out (or write your own) a menu script that you would want to use. This would be our mock-up. From there, it may be possible to implement automatic menu building from CMS depending on the code we are looking at.

Try going here: http://www.dynamicdrive.com/dynamicindex1/index.html or http://www.javascriptkit.com/script/cutindex23.shtml and looking at these menu scripts.

Let us know what you find

Kenny

Re: [sagentic] Active menu, and submenu

First level;

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

<?php if (!$categoryRecord['depth'] && $categoryRecord['_isSelected']): ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><font color="#4D0267"><?php echo $categoryRecord['name'] ?></font></a><br />
<?php endif; ?>

<?php if (!$categoryRecord['depth'] && !$categoryRecord['_isSelected']): ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a><br />
<?php endif; ?>

<?php endforeach; ?>

Second level, is in another place;

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

<?php if ($categoryRecord['_isSelected'] && $categoryRecord['depth']): ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><font color="#4D0267"><?php echo $categoryRecord['name'] ?></font></a><br />
<?php endif; ?>

<?php if (!$categoryRecord['_isSelected'] && $categoryRecord['depth']): ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a><br />
<?php endif; ?>

<?php endforeach; ?>

The second level menu is in the first level category. I would like the first level menu text to be marked as active when the second level menu is selected from this category.

Re: [solar_sys] Active menu, and submenu

By Dave - January 29, 2009

Hi solar_sys, welcome to the CMS Builder forum.

The software doesn't support that by default but you can add that feature yourself with some custom php code.

Note that this assumes you have a variable called $selectedCategory (which is the default configuration). $selectedCategory has a field called "lineage" which has a list of the record number for all the parent records. It looks like this ":1:6:23:". So we can check that. Here's some sample code:

<?php foreach ($lehe_ylesehitusRecords as $categoryRecord): ?>
<?php $isChildSelected = ($selectedCategory['num'] != $categoryRecord['num'] &&
preg_match("/:{$categoryRecord['num']}:/", $selectedCategory['lineage'])); ?>


Basically this means: If the current category isn't the one that is selected, but _IS_ an ancestor or parent of the selected record.

You can then test that variable to bold the parents:

<?php if ($isChildSelected): ?><b><?php endif ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a><br />
<?php if ($isChildSelected): ?></b><?php endif ?>

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

Re: [Dave] Active menu, and submenu

By solar_sys - January 29, 2009 - edited: January 29, 2009

That's good. It worked. There is one more thing I would like to get working. It is shortcuting - i have made a structure category section in admin. It has a list like this.... SELECT num, name FROM cms_lehe_ylesehitus .... with number and name. I have the same menu but i would like it to act so that when I choose a page from the list of my meny structure then it forwards a page to the second level page... it helps to avoid empty pages in the first level, instead it links the first level page to second level page.

Re: [solar_sys] Active menu, and submenu

<?php if (!$categoryRecord['depth'] && !$categoryRecord['_isSelected'] && !$isChildSelected && $categoryRecord['suuna_lehele'] != 0): ?>
<a href="<?php echo 'index.php?'.$categoryRecord['suuna_lehele'] ?>"><?php echo $categoryRecord['name'] ?></a><br />
<?php endif; ?>

<?php if (!$categoryRecord['depth'] && !$categoryRecord['_isSelected'] && !$isChildSelected && !$categoryRecord['suuna_lehele']): ?>
<a href="<?php echo 'index.php?'.$categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a><br />
<?php endif; ?>

Got it working like this! :)

Re: [solar_sys] Active menu, and submenu

One thing, that annoys me is the endless amount of whitespace characters in the source from browser view and that the code generator uses spaces instead of tabs. My index.php is nicely tab'ed and very correct, but in the view source the code is flooded with white space.

Re: [solar_sys] Active menu, and submenu

Dave - thank you for the sample code - it was really helpful! :)