Skip Navigation

[Resolved] How to not display an empty child view

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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

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

This topic contains 5 replies, has 2 voices.

Last updated by debraF 8 years, 8 months ago.

Assisted by: Waqas.

Author
Posts
#325282

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

My Child View:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
      <div class="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]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Parent view:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop> 
          <h4>[wpv-taxonomy-title]</h4> ----> (I want to not display this is nothing in the child view for this item)
          [wpv-view name="My Child View"] 
		</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]

Currently, it still shows the parent wpv-taxonomy-title even when the child view is empty.

example:

PARENT
child
child
child

PARENT - I want childless parents not to show in the list

PARENT
child

I would like to have it not display if there isn't anything in the child view - but don't know how to reference it using an "evaluate" statement. I've tried checking if the pdf-or-image-file field is empty, but that doesn't work because it doesn't know to look in the child view.

Thanks in advance!

#325444

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

You can do this by evaluating on [wpv-taxonomy-post-count], like below:

[wpv-if evaluate="[wpv-taxonomy-post-count] != 0"]
    ... your child view and title here ...
[/wpv-if]

Please see https://toolset.com/documentation/views-shortcodes/#wpv-taxonomy-post-count for more information.

#326037

I had tried the [wpv-taxonomy-post-count] shortcode but it still didn't work. What eventually did work after much trial and error and research was registering the following in my functions.php.

add_shortcode("clean-view", "clean_view");
function clean_view($atts, $content) {
    $content = do_shortcode($content);
    $content = trim($content);
     
    return $content;
}

Then adding [clean-view] on the Compatibility tab, then using this in my parent view.

		
          [wpv-if h1="[clean-view][wpv-view name='my-child-view'][/clean-view]" evaluate="!empty($h1)"]
          <h4>[wpv-taxonomy-title]</h4>
           [wpv-view name="My Child View"]
          [/wpv-if] 

Unfortunately, since I updated Views & Types today to the newest releases and then WordPress to 4.3, this no longer works and I no longer get anything displayed. (If I remove the [wpv-if], it works - so it is just the check against the child view that isn't working.) I tried the method above again using [wpv-taxonomy-post-count] , but it still displays the childless parents.

BTW - When I try to see the Views 1.10 release notes, I get a blank page. Please help!

#326115

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The nested short codes might be a problem with WordPress 4.3. I will suggest to use the following code, this is the same [clean-view] short code of yours, but with a slight modification:

add_shortcode("clean-view", "clean_view");
function clean_view($atts) {
    $view = $atts["view"];
    $content = render_view(array('title' => $view));
    $content = trim($content);
      
    return $content;
}

And use this short code as below:

[wpv-if h1="[clean-view view='My Child View']" evaluate="!empty($h1)"]
    <h4>[wpv-taxonomy-title]</h4>
    [wpv-view name="My Child View"]
[/wpv-if] 

Please notice the view name passed as the parameter to short code and render_view() function used in the short code function. Please read more about render_view() at https://toolset.com/documentation/user-guides/views-api/. Also remember to register [clean-view] in views settings.

The issue with release notes page (https://toolset.com/version/views-1-10/) has already been noticed and will be fixed soon.

Please let me know if I can help you with anything related.

#326268

Thank you! This did the trick. 🙂

#365099

I had help with this several months ago, but now the plugin has changed and this solution no longer works. I have tried changing my code to the following, but still am getting empty child views displayed.

[wpv-conditional h1="[clean-view view='Wine Fact Sheets']" if="( NOT(empty($h1)) )"]
          	<h4>[wpv-taxonomy-title]</h4>  
         	[wpv-view name="Wine Fact Sheets"] 
        [/wpv-conditional]

The forum ‘Types Community Support’ is closed to new topics and replies.

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