Mini Navigation Woe!

6 posts by 2 authors in: Forums > CMS Builder
Last Post: May 17, 2012   (RSS)

By Perchpole - May 15, 2012

It seems like I've been tackling this issue for ages but I just can't crack it.

I want to create a mini navigation menu that can be dropped into category pages to help users move back and forth between related pages.


Take a look at this category tree...

Home

About

Reviews
- Films
- Comedy
- Drama
- Sci-Fi
- Fantasy

- Books
- Crime
- Thrillers
- Horror
- Romance

Contact


What I want to do is place a mini menu in the margin of the "Films" page and on all of the pages beneath it in the hierarchy. The resulting menu would look like this:

Films
Comedy
Drama
Sci-fi
Fantasy

NB: The pages use the same template so the code which creates the menu must be applicable to all categories.

I thought it should be easy to create this simply by looping through all of the categories and then filtering through the results with if(): statements and _isSelected, _isParentSelected, _isSibblingSelected, etc...

However, this approach is proving fiendishly difficult to pull off cleanly because the relationship changes depending on which page of the hierarchy you select!

What I would like to do is come up with a solution in which I designate the category at the top of the hierarchy and then filter out the categories from that point down.

So, in my example, I would designate the "Films" category as the root of the mini menu. This tells CMSB where to start from - but how do I compile the rest of the menu?

It's not as straight-forward as it may at first appear!

:0/

Perch

Re: [Perchpole] Mini Navigation Woe!

By robin - May 15, 2012

Hey Perch,

If you set Films as your root category, it should just display what you've added in red. You have a different result? What does your getCategories call look like?

Thanks,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Mini Navigation Woe!

By Perchpole - May 15, 2012

Hi, Robin -

Thanks for your help.

I'm using a general getCategories call - which grabs every category. I need this for the main navigation system which is at the top of every page.

What I'm trying to do is (somehow) filter those results - further down the page - to return just those required for the mini nav.

It can be done (with a battery of if(): statements) but it gets horribly clunky!

As I said in my original post, I'm relying on a host of _IsSibblingSelected, _isAncestor, etc, etc, calls - but I suspect I'm not making best use of the ['breadcrumb'] and ['_lineage'] options.

:0)

Perch

Re: [robin] Mini Navigation Woe!

By Perchpole - May 15, 2012

OK, but I don't want to enter the Film num manually. I want to pass the value with some code. That way it will work on any page.

Lets assume I set up a checkbox on the category editor called "root". I would activate this for the "Films" category.

So, now if the page being viewed is the Films page I can use something like this to pass the value to the code:
<?php if ($selectedCategory['root']): ?>
...
'rootCategoryNum' => $selectedCategory['num']
...
etc


However, if the current page is a sub-category page - like the "Comedy" category - how do I look back up the hierarchy and assign the parent num to 'rootCategoryNum' ?

:0/

Perch

Re: [Perchpole] Mini Navigation Woe!

By robin - May 17, 2012

Hey,

If you always want the 2nd level category to be the root of the menu, you can find out it's num from the "lineage" field in your current category.
It's a comma separated field that will look something like this:
:17:19:20:

Hope that helps,
Robin
Robin
Programmer
interactivetools.com