Skip Navigation

[Resolved] Conditional Display of Heading and View based on return of View

This support ticket is created 4 years, 5 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Shane 4 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1638179

Tell us what you are trying to do? I have a Heading Block and a View Block... I would like them to be visible only if the View Block outputs some result. In case of nil output in the view, I'd like the Heading and the View to not be shown.. I can't figure out the Conditions that I should use in the IF Conditions.. Please help.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?hidden link

#1638697

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alim,

Unfortunately this is not possible to do as you cannot create a conditional statement based on the View Block output. The conditional block can only perform conditionals based on the post and custom fields.

So you wouldn't be able to achieve this setup of hiding the Heading block if the view doesn't return any results.

It is possible by using the Classic view setup and building your view using the classic editor, however this will require some css and html knowledge to achieve. In the classic view you can simply add the Heading in the [wpv-items-found] section and your heading will only show up when the view finds results.

If you're comfortable with HTML and CSS and want to try using the classic editor to achieve this please let me know.

Thanks,
Shane

#1638703

Hi Shane

It's almost 11 pm here in Bali..;-).. but yes I'd be interested in knowing how to achieve this using Classic Editor... I am decent with HTML and CSS..

I might not be online later .. but if you can send me some guideline on how to achieve this I will try it tomorrow morning..

Thanks again.. have a nice day..:-)..

Regards,
Alim

#1639079

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alim,

This one will be quite simple. So you will need to enable the classic editor by going to Toolset -> Settings then scroll to Editing Experience then select the option "Show both the legacy and Blocks interface and let me choose which to use for each item I build".

From there you can go to Toolset -> Views and create a new view. Select your data as you would.

Now when you reach the Loop Editor you will use your Loop wizard to set what data you want to be displayed. Once you have done this, in your loop wizard you will see some generated code similar to this below.


[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>

		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Within the [wpv-items-found] tag you can add your H1 title for your view. Example

[wpv-items-found]
<h1>My Title</h1>
	<!-- wpv-loop-start -->
		<wpv-loop>

		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]

Once you have done this your title will only display when the view has data to display.

Thanks,
Shane

#1639265

Thanks for the update Shane.. I'll try this out later today as I am prioritizing my other tickets for today..

In the meantime, can you tell me that when you put the H1 heading the way you did, would I have to style it separately? I mean in the Block Editor, I could centralise it, add a background colour and add padding, margin etc.. how would I 'beautify' the heading in a loop editor?

Also as the H1 tag is outside the 'loop' segment I am hoping the pagination animation will not affect the heading.. am I right? I mean if the VIEW content has a pagination and it displays 5 an then fades to another 5, I hope the H1 will remain steady and not get animated. Please do let me know if I am right or do we need to figure out some option for that.

Regards,
Alim

#1640123

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alim,

Unless your theme provides a default styling for the h1 tags then you will need to style it manually. All the beautification of the header would need to be done manually with CSS.

Also you are correct to assume that the pagination won't affect the header. The pagination only targets items that are inside the loop tags.

Thanks,
Shane