isSiblingSelected?

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

By Perchpole - June 30, 2011

Dave -

Just a thought...

Seeing as we have the entire family, could we not join them all together...

_isParentSelected
_isChildSelected
_isSiblingSelected
---------------------------------
=_isFamilySelected

...or is that a step too far?!

:0)

Perch

By Mikey - July 1, 2011

Perch,
I'm assuming this code goes in your page head:
<?php
$subMenuLinks = "";
foreach ($categoryRecords as $menuCategory) {
if ($menuCategory['_isSelected'] || $menuCategory['_isParentSelected'] || $menuCategory['_isChildSelected']) {
$subMenuLinks[] = $menuCategory;
}
}
?>


Do you mind provide some code showing how you build your categories in the body of your webpage. I'm struggling with it.

Thanks Zick

Hi, Zick -

I'm currently building a site for a large and long-established charity. As such, their "About Us" section contains upwards of 30 different pages across various sub-sections. I wanted to introduce a localised sub-section menu which would enable readers to move around the related pages.

The category tree looks something like this:

[pre]Home
Articles
News
About Us
Our History
Page2
Page3
Page4

Our Founder
Page2
Page3
Page4

Etc...
[/pre]

So, in our example, if a reader was on the "Our History" page, I wanted to display a small menu showing just those links related to that sub-section:

[pre]Our History
Page2
Page3
Page4[/pre]

Achieving this (with simple code) using the current filters was proving difficult. The _isAncestorSelected or _isDecendantSelected snippets returned too many links - often the entire branch of the ancestory tree.

With Dave's updates all I need is this:

<?php
$subMenuLinks = "";
foreach ($categoryRecords as $menuCategory) {
if ($menuCategory['_isSelected'] || $menuCategory['_isParentSelected'] || $menuCategory['_isChildSelected']) {
$subMenuLinks[] = $menuCategory;
}
}
?>


This pulls out only those links which are directly related to each category in the sub-section.

Works a treat!

:0)

Perch

Re: [zick] isSiblingSelected?

By Perchpole - July 20, 2011

Hi, Zick

Sorry for not responding sooner but I've been away...

In answer to your question, I have used the code above as follows:

<?php if($selectedCategory['paginate']): ?>
<?php
$subMenuLinks = "";
foreach ($categoryRecords as $subMenuCategory) {
if ($subMenuCategory['_isSelected'] || $subMenuCategory['_isParentSelected'] || $subMenuCategory['_isChildSelected'] || ($subMenuCategory['_isSiblingSelected'] && !$subMenuCategory['_hasChild'])) {
$subMenuLinks[] = $subMenuCategory;
}
}
?>
<ul>
<?php foreach ($subMenuLinks as $menuLink): ?>
<?php if($menuLink['_isSelected']): ?>
<li><b><a href = "./index.php?cat=<?php echo $menuLink['num'] ?>"><?php echo $menuLink['title'] ?></a></b></li>
<?php else: ?>
<li><a href = "./index.php?cat=<?php echo $menuLink['num'] ?>"><?php echo $menuLink['title'] ?></a></li>
<?php endif ?>
<?php endforeach ?>
</ul>
<?php endif ?>


I insert this into the page where I want to create the pagination menu.

Note the 'switch' at the top of the code to turn the menu on and off...

<?php if($selectedCategory['paginate']): ?>

This is a simple checkbox.

The code then scans each of the categories to see if it matches the _sibbling/_parent/_child criteria.

If there's a hit, the category is added to the $subMenuLinks array.

This is then used to create the foreach loop that defines the menu.

Does that help?

:0)

Perch