Closed Blasz closed 8 years ago
I have thought about this too and definitely think it is a good idea. In the GUI, it would not be a problem to implement (i.e. a condition group could be negated).
However, on the top off my head, I do not see how it is possible because the sidebar filtering is done in SQL, and the plugin will only "consider" contents/contexts that are relevant.
E.g. on a page, taxonomies will never be taken in to consideration, and on a post, page templates will never be taken in to consideration.
If you have a idea on how it could be done efficiently, please do make a pull request.
For your use case, have you tried the following:
Make a Sidebar B with condition group All Pages and Replace:Sidebar A
Make a Sidebar C with condition group
Of course, this would display Sidebar C instead of Sidebar A on the selected pages.
Having slept on it, I think it is easier to implement than I expected.
First, I filter the condition groups (as it is today) into Set A Then, I fetch all condition groups with a negation key into Set B Finally, I get all the groups that are either in Set A or Set B And the relevant sidebars can now be displayed
The reasoning is that if a group appears in both Set A and B, it means that its conditions are satisfied in the current context, but that it is negated and therefore should not be displayed. If it is only in Set A, then it should be displayed in this context. If it is only in Set B, then its conditions are satisfied in another context, but because it is negated, it should be displayed.
There might be an edge case I have not thought about, so it will need testing.
This has been implemented as of 96704db
It would be nice to be able to apply negation conditions to the sidebar displaying as per https://wordpress.org/support/topic/how-do-i-negate-a-condition
It would be desirable to show a sidebar on all pages except certain ones.
My current use case for this is wanting to display a sidebar on all pages that do not use a certain page template (effectively all pages with the default page template). I can only do this by manually adding each page to a condition group resulting in maintenance when new pages are added or by creating another custom template that is the same as the default one that would then be applied to each of the 'default' pages.
I don't think either workaround is satisfactory.
I can potentially make a pull request for this if need be.