I am working on a custom theme, basically migrating a current sites look and feel into WordPress. Most of everything is based on Pages, and all of these pages should have a left sidebar. Of those pages, they are one of the 3 below:
- Page is part of a section, so shows a list of all parts of the section in a widget
- Page is part of a section, so shows a list of all parts of the section in a widget, but also has children, so displays those pages in a seperate widget above.
- Page isn't part of a section, so has no sibling or children pages.
I don't want to have to make a separate page template for those that are in #3. Currently, something in #3 won't render anything, except an aside that contains the get_sidebar()
function. If this is the case, instead I would like to list all sections, so I have something there.
I can't seem to find any good examples of this. Of all the core functions, they seem to look to see if that sidebar contained widgets in the sense of available in the sidebar - not actually rendered (unless I am missing something). I also tried setting a variable in the widget and read it on the page, but that didn't seem to work either.
How can I conditionally display an extra widget if no others are displayed? Or, if I added this widget to it anyways, hide it if any other widgets are rendered in the same sidebar?
Update: When I state 'none displayed', I mean in such that the widget doesn't echo something back. For example, my widget gets a list of things to display. If the list is empty, I already have conditional logic that doesn't render (or echo anything out) the widget. An example is below:
$subpages = wp_list_pages('title_li=&child_of='.$thisPageID.'&echo=0&depth=1');
if($subpages)
{
// I have subpages, so display them
echo $subpages;
}
else
{
// no subpages, doesn't echo anything.
}
If it hits the else, and nothing is rendered, im wondering if there is some logic I could use in the sidebar to know I got nothing back, and then render something else to take its place.
Another way of looking at it would be say I have a default widget, a list of everything. But, if I have any other content to display, I hide the default widget, and display that instead. Therefore, every page would have something on it.
Update 2: A friend brought up an idea I previously didn't think of - this widget could just have the opposite of the logic that made it render one of the previous ones - rather than relying on the output of the previous ones. Therefore, since the two would mutually exclusive, all pages would render what they should. In this simple example, that would work. I am still very curious if there is a way to test if a widget echo'd something.
echo
es something?