Category Menus - How to highlight active button

13 posts by 4 authors in: Forums > CMS Builder
Last Post: February 28, 2011   (RSS)

Re: [jkoveos] Category Menus - How to highlight active button

By Jason - February 22, 2011

Hi,

There are a couple of ways of going about this depending on how you're generating your menu.

If you could attach your .php file that displays your menu, I can take a look and can give you a more specific example.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Category Menus - How to highlight active button

By (Deleted User) - February 22, 2011

Here is the menu that is on the site.
Attachments:

menu.php 2K

Re: [jkoveos] Category Menus - How to highlight active button

By Jason - February 23, 2011

Hi,

What you can do is on each of your .php page, you can set a $_REQUEST variable just before you include menu.php.

For example:
<?php $_REQUEST['currentPage'] = "/index.php"; ?>
<?php include("menu.php");?>


You can then compare this variable to the url of the url field in your category menu like this:

<div class="menuh">
<ul>
<?php foreach ($menuhRecords as $record): ?>
<?php echo $record['_listItemStart'];?>
<a href="<?php echo $record['url'] ?>" <?php if(@$_REQUEST['currentPage'] == $record['url']) { echo 'class = "active"';} ?> ><?php echo $record['name'] ?></a>
<?php echo $record['_listItemEnd'];?>

<?php endforeach ?>

<?php if (!$menuhRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
</ul>

</div>


Hope this gets you started. You may need to change this code depending on how you're using your CSS.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Category Menus - How to highlight active button

By aev - February 24, 2011

Hi,

isn't the $categoryRecords['_isSelected'] meant to be used for handling this?

I use this field in conjunction with the new ulAttributesCallback/liAttributesCallback introduced in CMSB 2.06 to handle category menus.

-aev-

Re: [aev] Category Menus - How to highlight active button

By Jason - February 24, 2011

Hi,

Yes, you can use _isSelected, but to do that, the link you click on has to pass something in the url that specifies which category link was just clicked. In code provided, they're using a text field called url to create the link.

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/

Re: [Jason] Category Menus - How to highlight active button

By zip222 - February 27, 2011

I have another question about the category records.

I have a menu that allows up to two levels. When a second level page is selected I want the parent to also stay highlighted. example...

Home
About
- Company
- Vision (selected)
- Staff
Products
Services

If i am on the "Vision" page, I want "Vision" and "About" to both be highlighted. How do I do this? Here is the code I am currently using:

// load main navigation
list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'pages',
'categoryFormat'=> 'onelevel',
));


<ul>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<?php if ($categoryRecord['_isSelected']): ?>
<span class="current">
<a href="?page=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
</span>
<?php else: ?>
<a href="?page=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php endif; ?>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>

Re: [zip222] Category Menus - How to highlight active button

By aev - February 28, 2011

Hi,

maybe you can use the _isSelectedBranch field.

Try changing your line 4 to this:
<?php if ($categoryRecord['_isSelected'] || $categoryRecord['_isSelectedBranch']): ?>


Here are some more fields you can use when checking category relations:

_isSelected
_isAncestorSelected
_isDescendantSelected
_isSelectedBranch
_hasParent
_hasChild
_isFirstChild
_isLastChild
_hasSiblings



-aev-

Re: [aev] Category Menus - How to highlight active button

By zip222 - February 28, 2011

Thanks. The variable I was looking for was _isDescendantSelected. This is super helpful.

Re: [zip222] Category Menus - How to highlight active button

By zip222 - February 28, 2011 - edited: February 28, 2011

Follow up question...

how do I force the first menu item to be selected when first arriving to the page? The correct page is being displayed, but it isn't being highlighted in the menu... unless I click on it, which updates the URL to include the pages "num"

See page:
http://lasasections.jasmardesign.com/template/