Skip Navigation

[Resolved] Show Titles that Have Child Hide Titles that Have No Child

This support ticket is created 5 years, 1 month 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 3.03 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)

Tagged: 

This topic contains 7 replies, has 3 voices.

Last updated by Waqar 5 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1356777

Tell us what you are trying to do?
I want to show only the Titles that have children under it...contents...while the empty to disappear...but reappear when there’s a content became under it.

Is there any documentation that you are following?
No.
Is there a similar example that we can see?
No.
What is the link to your site?
hidden link

#1356779

My creds to login are in the previous ticket you replied days ago.

#1357029

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You want to conditionally display the title according to whether the current post has child posts or not.

So you will need to wrap the title in wpv-conditional shortcodes. To understand those, refer to https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

But what should the condition be?

Well, you can create a View to display child posts which just outputs the count of found posts, with the wrapper div disabled.

You can run into issues with whitespace in the output, so an alternative would be to add the following code to register a custom shortcode "connections":

/**
 * Register connections shortcode
 *
 * @att (string) relationship : post relationship slug
 * @return count of connected posts
 */
add_shortcode( 'connections', function( $atts = [] ){
  
    // provide defaults
    $atts = shortcode_atts( 
        array(
            'relationship'      =>   '',
        ), 
        $atts
    );
  
    global $post;
    $count = 0;
  
    $relationship = toolset_get_relationship( $atts['relationship'] );
  
    if ( $relationship ) {
  
        $parent = $relationship['roles']['parent']['types'][0];
        $child = $relationship['roles']['child']['types'][0];
        $type = $post->post_type;
  
        $origin = ( $parent == $type ) ? 'parent' : 'child';
  
        // Get connected posts
        $connections = toolset_get_related_posts( $post->ID, $atts['relationship'], array(
        	'query_by_role' => $origin,
        	'role_to_return' => 'other',
        	'need_found_rows' => true )
    	);
    	$count = $connections['found_rows'];
  
    }
  
    return $count;
});

To use it you just need to specify the relationship slug as an attribute, e.g.

[connections relationship="project-task"]

would show how many tasks are children of the current project.

To use it with conditional shortcodes, you first need to register the custom shortcode at Toolset > Settings > Front-end Content.

Then you can create a condition such as

[wpv-conditional if="( '[connections relationship='project-task']' ne '0' )"]
<p>This project has some tasks</p>
[/wpv-conditional]

Naturally, you'll need to use the correct slug for your relationship.

#1357067

We have already Views setup & working collapsible.
So what I want is to remove the titles that aren't having children. Not collapsible but disappears...while the ones that will have children to appear.
Please have a look you'll unserdstand.

#1357117

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I don't have access to your site.

Which part of the above do you not understand?

If you have a View that is outputting parent posts in collapsible sections, then the markup which inserts a collapsible section should be wrapped in the wpv-conditional shortcode as described above.

Please check the documentation link I shared to understand how the wpv-conditional shortcodes work.

Note this specific section describes registering a custom shortcode for use in conditional shortcodes: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes

#1357839
Screenshot_20191008-134536.png
Screenshot_20191008-134044.png

Sorry I don't know how to do it...when we created the View someone helped me from your end...we aren't developers.
So please helo me.
I am attaching one image contains children in hierarchy...ends by no. 536

Another image no. 044 has empty title; I mean has no child...in this case we want this title to disappear from the view...but appears un the future if we added child under it.
You can send the private Message to give you creds or find them from my previous ticket.
Thanks a lot.

#1357943

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

We don't keep site credentials on closed tickets, so I'll need to get the again from you.

I've set up a private reply.

Which is the View that generates this output?

#1360441

Hi.

Thanks for writing back and for sharing the admin access.

Nigel is on vacation and will be back on Monday, so I'll be following up on this ticket.

To make sure only parent accordion titles with some results within are shown, you can follow these steps:

1. In your view "Parent - SN - Ar - Subjects", please replace the main div container in the "Loop Editor" section from:


<div class="panel panel-default>

To:


<div class="panel panel-default panel-main panel-[wpv-taxonomy-id]">

This way all the parent or main accordion containers will be different from the child ones and will also have a class with an ID, to make each one unique.

In the "CSS editor" tab below, also include this CSS code which will hide all these, parent or main accordion containers, initially:


.panel-main {
  display: none;
} 

Screenshot: hidden link

2. In your nested view "Posts - SN - Ar - Subjects", include the following custom CSS code, right after the [wpv-items-found] tag in the "Loop editor" section:


<style type="text/css">
.panel-main.panel-[wpv-attribute name='pid1'] {
  display: block;
} 
</style>

Screenshot: hidden link

As a result, only those, parent or main accordion containers will become visible, which will have at least one result in them and others will stay, hidden.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar