Home › Toolset Professional Support › [Resolved] Hide widget box when view has no content
Problem:
Can I hide or show parts that are not the content of my theme (widgets, header, footer, etc) depending on a view's output or similar?
Solution:
Only applying custom code, since the Theme's parts mentioned (widgets, header, footer, etc) are part of the theme and not the content (the_content()) which can be styled and edited with Toolset.
You would need to create a Child or Custom Theme and hide/show the sections according to results received from PHP calls to the Views or other data providers used.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
Tagged: Views, Views plugin
This topic contains 4 replies, has 2 voices.
Last updated by matthewL-7 5 years, 10 months ago.
Assisted by: Beda.
Hi,
Is there a way we could hide a widget box when the view has no content?
I have been trying to think of a way to do this but can't think how it could be possible?
If you look here on the right hand side widget bar for example: hidden link
You will see below the ad that there is a white line, here widget content appears when the widget has relevant content but when it doesn't I don't want this white line appearing.
Is there a way I could have this now show up?
Or maybe a way how I could at least have some CSS have the background color as clear BUT only when there is no content to display?
Thanks.
If by Widget Box you mean the Sidebar of a theme where you can add Widgets, then no, because Toolset cannot edit or alter that area.
It only applies to the Post Body - which in technical terms is the_content() or any function rendering it.
I see that you put the View in a Widget area, but that does still not allow to customize that widget area itself.
It only allows to show the View in the widget area but not to alter the widget or the area itself.
One solution can be to output something that you like better than the empty space in the "no items found" section of the view.
This way, if the View has results you will see those, if not then you would see your content added to the "no items found"
Yeah I would rather display nothing though than a message saying no items found.
I could have the background of the widget area clear, could then if the content loads the background be set? Would that work? Is this not an issue anyone else has come across before?
Matt
Well, that all depends on what you put (manually) as HTML and CSS to the View's Loop "Items Found" and "No items found" section.
For example, you can wrap the items found the section in a Specific DIV and add specific CSS that shows some background, and then the "no items found" case will not show that background.
Managed to do it, a little messy but achieved it. 🙂