I recently came across a situation where I needed to show a sidebar on a page template, if the page has childeren. Consequently I also had to check if the current page was such a child, and if so show the same listing from the parent (which are ‘sibling’ pages at this point).
To do this I created two functions in my
The first one checks if the current page has childeren, the second checks if the current page has parents. I could combine these into one function, but I figured I might need either one later.
In my page template I set up the columns with Bootstrap like so
And to list either the child pages or sibling pages I wrote this piece of code:
The main magic here is in the php shorthand to check if the page is a child (and then get parent page, and those childeren) or else (page is a parent) just show the kids.