Skip Navigation

[Resolved] Conditional to check if either of multiple views has results

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Our next available supporter will start replying to tickets in about 0.22 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by matthewC-9 3 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2013927

Hi! I'm working on a site using classic Views. In one of my content templates, I'd like to create a conditional to check whether either of 2 different views has results for the page in question, then display output based on the results. (The views already exist and work in the context of the page - I'm trying to add some wrapping markup only if they have results.) What's the best way to do this?

Thanks!
Sarah

#2014391

Hi Sarah,

Thank you for contacting us and I'd be happy to assist.

To suggest the most efficient way to achieve this, I'll need to see how these views are being placed on the page and where the conditional wrapper needs to be.

Can you please share temporary admin login details, along with the link to the page where these can be seen?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#2016161

Thank you for sharing these details.

Looking into the content template, I understand that you'd like to show the div with class "page-sidebar", only when some content exists inside it.
(that content can be from either of the two views or the field "event-feed")

The most efficient way I can think of would be to include some custom script in the content template's "JS editor" which can look for a presence of a div element inside the div with class "page-sidebar", and if none exists, hide it.
( screenshot: hidden link )


jQuery(document).ready(function(){
	if( jQuery('.entry-content div.page-sidebar div').length == 0 ) {
		jQuery('.entry-content div.page-sidebar').hide();
	}
});

#2016233

Well, huh. 🙂 I hadn't thought of doing it that way, but that certainly is simpler. I'm generally trying to make sure everything still works without JavaScript, but - since this is mostly just to control the page layout, it seems perfectly reasonable to treat it as an enhancement - someone without JS won't get any different content, just a slightly different layout. That seems perfectly fine to me.

My issue is resolved now. Thank you!