isSiblingSelected?

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

By Perchpole - June 27, 2011

Hello, All -

I'm trying to develop a localised menu to display links to related categories. I've tried using various built-in getCategories() code snippets as filters, such as _isAncestorSelected and _isSelectedBranch, etc., but the results aren't always as expected (when dealing with multi-tier category trees).

What I'd really like is something which would work along the lines of _isSiblingSelected.

This code isn't yet built into CMSB - so is there any way I can mimic it?

:o/

Perch

Re: [Perchpole] isSiblingSelected?

By Dave - June 28, 2011

Hi Perch,

I can add that to the next version and give you some code for it. How would we define _isSiblingSelected? All records at the same depth with the same parent as the selected category?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] isSiblingSelected?

By Dave - June 28, 2011

Or maybe just all categories with the same parent category as the selected category?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] isSiblingSelected?

By Perchpole - June 28, 2011

Hi, Dave -

That sounds perfect and would make an excellent filter.

So would _isParentSelected

It's a bit of a more specific than _isAncestorSelected.

Can we add that to you list too, please?!

:0)

Perch

Re: [Perchpole] isSiblingSelected?

By Dave - June 28, 2011

Hi Perch,

Try this:
- Open lib/viewer_functions.php
- Search for _hasSiblings
- Add the code in red:
$category['_hasSiblings'] = intval( !($category['_isFirstChild'] && $category['_isLastChild']) );

// added in 2.10
$category['_isSiblingSelected'] = intval( $selectedCategory && $selectedCategory['parentNum'] == $category['parentNum'] && !$category['_isSelected'] );
$category['_isParentSelected'] = intval( $selectedCategory && $selectedCategory['num'] == $category['parentNum'] );


$category['_listItemStart'] = _getListItemStartTags($prevCategory, $category, $nextCategory, $options);


Hope that helps, let me know if that works for you!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] isSiblingSelected?

By Perchpole - June 29, 2011

Dave -

Brilliant. Thanks for this. It works really well.

Can we complete the deck and have _isChildSelected?

Again, it would be a bit more specific than _isDecendantSelected.

:0)

Perch

Re: [Perchpole] isSiblingSelected?

By Dave - June 29, 2011

Hi Perch,

Sure, try this:

$category['_isChildSelected'] = intval( $selectedCategory && $category['num'] == $selectedCategory['parentNum'] );

Let me know if you need any other changes, otherwise I'll include these all in 2.10.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] isSiblingSelected?

By Perchpole - June 29, 2011

Dave -

This is great. Better than great! Thanks.

:0)

Perch

Re: [Perchpole] isSiblingSelected?

By Mikey - June 29, 2011

Dave -

This is great. Better than great! Thanks.

:0)

Perch


Perch, can you provide some code showing how this came together... I thick this is just what I've been searching for.
Zick