I'm trying to build a sidebar menu displaying child pages of a grandparent page, his siblings and their childs, and keep those siblings and childs available while navigating through them.
I've been looking at different and similar posts at the forum, but so far I haven't had any luck with an exact solution or something I can tweak to achieve this.
This is my pages estructure:
- Services
- Service One
- Service One About
- Service One Sub-Services
- Sub-service One A
- Sub-service One B
- Sub-service One C
- Service Two
- Service Two About
- Service Two Sub-Services
- Sub-service Two A
- Sub-service Two B
- Sub-service Two C
- Service One
What I'm trying to do is:
If I'm in "Service One About", I should only show "Service One About", his siblings and its childs.
- Service One
- Service One About [current]
- Service One Sub-Services
- Sub-service One A
- Sub-service One B
- Sub-service One C
If I'm in "Service One Sub-Services", I should only show "Service One Sub-Services", his siblings and its childs.
- Service One
- Service One About
- Service One Sub-Services [Current]
- Sub-service One A
- Sub-service One B
- Sub-service One C
If I'm in "Sub-service One A", I should show his parent and uncle, and his siblings.
- Service One
- Service One About
- Service One Sub-Services
- Sub-service One A [current]
- Sub-service One B
- Sub-service One C
And so on.
That said, in case it's not clear: I wan't to exclude the "Service" grandparent, as well as the whole "Service Two" branch while I'm navigating through "Service One" and viceversa.
It is very important for me to control the output of each level because I have created a custom field on the pages to use it as a CSS class. For this I'm using Toolset Types & Views and I'm planning to print this as an <?php echo do_shortcode('[some-custom-field-shortcode]') ?>
as shown on the example below.
Also, it would be great if I could add a class to the current menu item, so I could mark it as the current item.
Based on my "Sub-service One A" example above, this is how my output markup should look like:
<ul class="menu">
<li><a href="#">Service One About</a></li>
<li><a href="#">Service One Sub-Services</a>
<ul class="sub-menu">
<li class="current-menu-item"><a href="#"><span class="icon [some-custom-field-shortcode]"></span> <span class="text">Sub-service One A</span></a></li>
<li><a href="#"><span class="icon [some-custom-field-shortcode]"></span> <span class="text">Sub-service One B</span></a></li>
<li><a href="#"><span class="icon [some-custom-field-shortcode]"></span> <span class="text">Sub-service One C</span></a></li>
</ul>
</li>
</ul>
Could you please give me a hand with this? I've been really fighting to achieve this with Types & Views, but their forum doesn't seem to help (other users had asked similar questions and most of them just got frustrated and ended up using a plugin like this.
Thank you so much in advance! :)
wp_list_pages
can not handle as it is. The only way is defining a custom walker (see walker argument) to override the output or, due the high customization, make your own function. By the way, I think that the data structure you have make it harder; for example, what is logic that make "Service One About" a sister page of "Services Two Sub-Services"?. Maybe you can rethink about the data structure.