Skip Navigation

[Résolu] Hide title if loop is empty

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to use a conditional to determine whether or not to display some text based on whether or not the View returns any results.

Solution: If the loop returns no results, then the title will not show if the h4 tag is placed inside wpv-items-found:

[wpv-items-found]
...this content only appears when results are found
[/wpv-items-found]

If you want to suppress the View entirely on posts that have category "d", then you would wrap the View's shortcode in a conditional that tests whether or not the post has a specific term:

[wpv-conditional if="( has_term('d', 'category', null) ne '1' )"]
   ... your View shortcode here
[/wpv-conditional]

Replace "d" with the actual term slug, and 'category' with the taxonomy slug. Then you must register the has_term function in Toolset > Settings > Frontend Content > Functions inside conditional evaluations.

Relevant Documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/digging-into-view-outputs/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

This support ticket is created Il y a 6 années et 8 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 réponses, has 2 voix.

Last updated by hugoC-3 Il y a 6 années et 8 mois.

Assisted by: Christian Cox.

Auteur
Publications
#563191

I have a related posts view that is to be applied to some, but not all post categories:

<!-- wpv-loop-start -->
<h4 class="widgettitle">Related posts</h4>
<div width="100%">
<wpv-loop wrap="3" pad="true">
[wpv-item index=1]
<div class="one-third first">
[wpv-post-body view_template="Loop item in Related posts"]
</div>
[wpv-item index=other]
<div class="one-third">
[wpv-post-body view_template="Loop item in Related posts"]
</div>
[wpv-item index=3]
<div class="one-third">
[wpv-post-body view_template="Loop item in Related posts"]
</div>

[wpv-item index=pad]

[wpv-item index=pad-last]

</wpv-loop>

A post in categories a, b or c shows related posts from the category the post belongs to.
But a post in category d should'nt show the view at all; now it displays the title with an empty loop.

How can I set up a conditonal to hide the title if the loop is emtpy?

#563284

How can I set up a conditonal to hide the title if the loop is emtpy?
If the loop returns no results, then the title will not show if the h4 tag is placed inside the

[wpv-items-found]
...this content only appears when results are found
[/wpv-items-found]

block of your Loop.

If you want to suppress the View entirely on posts that have category "d", then you would wrap the View's shortcode in a conditional that tests whether or not the post has a specific term:

[wpv-conditional if="( has_term('d', 'category', null) ne '1' )"]
   ... your View shortcode here
[/wpv-conditional]

Replace "d" with the actual term slug, and 'category' with the taxonomy slug. Then you must register the has_term function in Toolset > Settings > Frontend Content > Functions inside conditional evaluations.

Let me know if you have additional questions about that.

#563286

Edit - I modified the code above slightly, you may need to copy + paste again if you had already copied it.

#563643

Thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.