Closed Android63 closed 6 years ago
I don't think this is a new template? It's just logic to not output the sidebar markup if no widgets are active? Widget visibility can be controlled by widget logic from either the widget logic plugin or as part of JetPack.
Not sure @cehwitham. What if some pages need a sidebar and some don't? For the ones that don't, we should display an empty sidebar whether or not the sidebar contains widgets.
I suppose there are two ways to do it.
"No sidebar" template file. Basically same as the main template, we just remove the get_sidebar call. People can then set their page to use the "No sidebar" template. Easy for people to change template, only works for pages not posts.
Within the sidebar template, we test to see if any widgets are active. If not, don't output any markup, if they are, output the sidebar and widgets. We could then use something like widget logic (plugin) or the logic added to widgets by Jetpack to control which plugins display on which pages/posts. Works for all content types and gives much better granular control. If widget logic or JetPack aren't installed then it'll just output the sidebar if widgets are active. People can choose which logic plugin they want to use, JetPack or widget logic or another. Slightly more complicated to set up for the user as they have to edit the widgets, not just the pages.
Maybe we implement a combination of both?
I like option 2 because of its granular control. I can imagine a scenario when certain widgets only apply to certain pages. In fact, the LDP Hub has exactly that requirement: the evaluation reports page needs category and tag filtering, which no other page needs. But the home page may, for example, need a latest posts widget.
A combination of both would also work, but I wonder if it might get confusing for admins. I guess we could add option 1 later..?
I think we could possibly end up with other page templates in the future, either for homepage or landing pages. So keeping the logic in the widgets stuff not the page templates stuff makes sense too.
Jetpack's widget visibility feature seems more user-friendly than the widget logic plugin since the former uses drop-down lists, etc. and the latter requires admins to enter php code.
...not that it makes any difference to the theme. We can include recommendations in the documentation and let users choose what they prefer.
Some won't want to install JetPack as it connects to WordPress.com and shares some info. JetPack Lite or similar might work. But, as you say, we can setup the theme and have a preference on plugin but let people make their own decisions.
Thinking about this again, I wonder if there's any need to test to see if there are any active widgets since we need a sidebar anyway, even if it's empty. Or have I missed something @cehwitham?
Following our chat I get it now @cehwitham. We should avoid outputting empty markup.
Since some pages don't need any sidebar content, but Nightingale demands a sidebar to be present anyway, even if it's empty, we need a template that includes the sidebar but without the contained widgets.