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: [Perchpole] Mini Navigation Woe!

By robin - May 15, 2012

The "rootCategoryNum" parameter might be exactly what you need. Just use the num of "Films" instead of 0

e.g:

list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'category',
'rootCategoryNum' => '0', // Only categories _below_ this one will be shown (defaults to 0 for all)


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

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