category menu active page

6 posts by 3 authors in: Forums > CMS Builder
Last Post: July 12, 2011   (RSS)

By buttermilk - July 7, 2011

Hi all,

I've been trying to figure out how to deactivate the link in whatever entry is being viewed by the user in a category menu section editor.

I'll try and elaborate so that makes more sense.

I've got a simple category menu that has only two levels. As it stands now, all the entries in the menu (both parent and child levels) are active links. I'd like to change that so when the viewer is reading the "community programs" entry in the detail viewer the corresponding link in the navigation is simple text rather than a link.

Here's my php code:

<div>

<?php foreach ($about_usRecords as $record): ?>

<?php if ($record['depth'] == 0): ?>
<div style="display:inline; margin-right:5px;"><a href="about_us.php"><?php echo $record['name'] ?></a></div>

<?php else: ?>

<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>

<?php endif ?>

<?php endforeach ?>
</div>


Here's a link to where I've been torturing myself with this. [crazy]
It's been driving me crazy! Thanks in advance for any help.

http://74.52.72.36/~jocotoco/about_us.php

Ian

Re: [buttermilk] category menu active page

By Dave - July 7, 2011

Hi Ian,

Can you attach the about_us.php file so we can take a look? Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] category menu active page

By buttermilk - July 8, 2011

Sure thing. I'm sorry if this code is nuts.
Attachments:

about_us.php 4K

Re: [buttermilk] category menu active page

By Dave - July 11, 2011

Hi Ian,

It looks like you always have a list of all your records in $about_usRecords, and you have your selected record defined as $about_usRecord (no s). And when you loop over "all" the records in the foreach you refer to each individual record as $record. So you should be able to check if the menu link you are displaying is selected like this:

<?php if ($record['num'] == $about_usRecord['num']): ?>
selected
<?php endif ?>


That's basically saying, if the record we're displaying in the menu has the same record number as the selected record then print "selected".

It's a bit easier to read if you assign that to a variable. Here's some easier to read code:

<?php foreach ($about_usRecords as $record): ?>
<?php $isSelected = ($record['num'] == $about_usRecord['num']); ?>

<div style="display:inline; margin-right:5px;">

<?php if ($isSelected): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a>
<?php else: ?>
<?php echo $record['name'] ?>
<?php endif ?>

</div>

<?php endforeach ?>


Hope that helps! Give that a try and let me know if you get any further, and any questions or problems with it.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] category menu active page

By buttermilk - July 11, 2011

Hi Dave,

Thanks so much for helping me out.

This works for the "about_us.php" page, but my problem, I see now, is really with "about_us_detail.php" page.

When I go to any of those other entries in the "about_us" section editor the corresponding link remains active. How would I go about deactivating the link for the respective entries of that link?

I've attached the "about_us_detail.php" page. Any help you can provide is greatly appreciated!

Ian
Attachments:

about_us_detail.php 4K