Skip Navigation

[Resolved] Hiding empty child views no longer working with new wpv-conditional tags

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to hide parent title if parent has no child available

Solution:
You should simply use jQuery code to hide the parent title which do not have any child.

You can find suggested solution with the following reply:
https://toolset.com/forums/topic/hiding-empty-child-views-no-longer-working-with-new-wpv-conditional-tags/#post-366836

Relevant Documentation:

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

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by debraF 8 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#366030

I am trying to to not display a parent taxonomy if the child view has no records found.

I visited this URL: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ but it does not address how to hide empty child views.

Here is my page. I want the wines without download files (child view [wpv-view name="Wine Fact Sheets"]) to not show the headings.

This used to work: https://toolset.com/forums/topic/how-to-not-display-an-empty-child-view/

But with the recent update, it no longer did. So I am trying to change to the new wpv-conditional tags.

Here is what I have in my parent view (Fact Sheets by Wine)

	<!-- wpv-loop-start -->
		<wpv-loop>  
	                [wpv-conditional if="([wpv-view name='Wine Fact Sheets'] ne '' )"]
                                <h4>[wpv-taxonomy-title]</h4>  
                                <div id="wine-view">[wpv-view name="Wine Fact Sheets"]</div>
                          [/wpv-conditional]
		</wpv-loop>
	<!-- wpv-loop-end -->

I've also tried using NOT empty, and adding the [clean-view] but those didn't work either.

And here is what I have in my child view (Wine Fact Sheets):

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
      <div id="downloads">
         <a href="[types field='pdf-or-image-file'][/types]" target="_blank">[wpv-post-title]</a><br />
      </div>
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
[wpv-no-items-found][/wpv-no-items-found]
[wpv-layout-end]

with this in the JS Editor

jQuery(document).ready(function($){             
 length_b = $('#downloads > a').length;   
if(length_b==0){   
  $('#downloads').hide();
}                      
});
#366082

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I think the issue here is that you have put div with ID "download" within the loop.

Could you please try following code:

[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
<div id="downloads">
    <wpv-loop>
               <a href="[types field='pdf-or-image-file'][/types]" target="_blank">[wpv-post-title]</a><br />
          </wpv-loop>
</div>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-no-items-found][/wpv-no-items-found]
[wpv-layout-end]

As you can see I've put your div outside the "<wpv-loop>".

And add the same JS to JS box:

jQuery(document).ready(function($){             
 length_b = $('#downloads > a').length;   
if(length_b==0){   
  $('#downloads').hide();
}                      
});

I hope this will fix your issue. Please let me know your feedback and do not hesitate to get in touch with me if your issue still persist.

#366400

I swapped out the code with what you provided for both the layout and the JS, but now I don't get anything on that page.

hidden link

#366451

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I reviewed your page:
=> hidden link

You mean to say if there is no content in child view you want to hide "Wine Fact Sheets" tab?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#366836

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

No need to write if condition now and give load to server.

I've added simple jQuery code to accomplish your goal. I've added the following code to your views JS box.

jQuery(document).ready(function($){             
  $( "div.downloads").not(':has(a)').hide()
});

I hope this will fix your issue and please feel free to open a new ticket for for your each new question.

#366990

Perfect! This did the trick. Thank you!

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