category menu active page

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

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

Re: [buttermilk] category menu active page

By robin - July 12, 2011

Hi Ian,

Something like this should help you with your link formatting. It does not create a link if the num of the current record equals the num of the record in the loop.

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

<?php if ($record['depth'] == 0): ?>
<?php if ($about_usRecord['num'] != $record['num']): ?>
<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;"><?php echo $record['name'] ?></div>
<?php endif; ?>

<?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 ?>


Hope that helps,
Robin
Robin
Programmer
interactivetools.com