Skip Navigation

[Resuelto] Conditional Logic Based on Number of Child Taxonomy Terms

This support ticket is created hace 1 año, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por Minesh hace 1 año, 2 meses.

Asistido por: Minesh.

Autor
Mensajes
#2641945
Screenshot 2023-09-07 at 16-30-22 Product Categories - KML Industrial Supply Inc.png

I'm a product category structure where terms are expected to have several layers of children and I'm trying establish a conditional logic argument that checks against the current term's number of child terms. Here's the page in question: enlace oculto

Basically I want my conditional to have a statement with something like "if taxonomy term children count > 0"

Currently, I have a view that outputs the number of found terms in its output (showing 1 item per page) and I'm using that for my argument to determine the number of child terms a given term may have.

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          	[wpv-found-count]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		0
	[/wpv-no-items-found]
[wpv-layout-end]

And then I've inserted it into the conditional logic in my primary view here:

<ul>
<!-- wpv-loop-start -->
    <wpv-loop>
        <li class="product-cat-list-item">
            <a href="#" class="product-cat-has-children">[wpv-taxonomy-title]</a>
            [wpv-conditional if="( '[wpv-view name='product-category-term-count']' gt '0' )"]
                <ul>
                    [wpv-view name="product-categories-landing-grandchildren"]
                    <li class="product-cat-list-item view-all">
                        <a href="[wpv-taxonomy-url]">View All [wpv-taxonomy-title]</a>
                    </li>
                </ul>
            [/wpv-conditional]
        </li>
    </wpv-loop>
<!-- wpv-loop-end -->
</ul>

I'm getting a number output when I put my term count view outside the conditional (see attachment), however I tried various argument validations and none seem to be providing the behavior I'm looking for.

- gt '0' gets me no results
- gte '1' gets me no results
- ne '' gets me all the things regardless of number of actual terms
- ne '0' gets me all the things as well

In my screenshot, the term "Indexable" should be the only list item with visible child list elements as it's currently the only one with child terms.

Any help in this matter would be greatly appreciated. Thanks in advance!

#2642093

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Here is the Doc that shows how you can group posts by category or taxonomy using nested view (view inside view):
- https://toolset.com/2015/07/how-to-group-posts-by-category/

Can you please tell me why you need conditional logic? Do you mean you want to display first category and then sub-category with its associated post count - for example:
Category 1
- sub-cat-1 (10)
- sub-cat-2 (15)
Category 2
- sub-cat-3 (1)
- sub-cat-4 (5)
Category 3
- sub-cat-5 (0)
- sub-cat-6 (2)

#2642263

I need a "View All {product category name}" link nested within the child unordered list and putting that within the nested view didn't work. This is what I'm trying to achieve:

<ul>
    <li>Indexable
        <ul>
            <li>Child 1</li>
            <li>Child 2</li>
            <li>Child 3</li>
            <li>View All Indexable</li>
        </ul>
    </li>
</ul>

The conditional logic is necessary as there's a possibility that a product category will not have any child terms, and I need to alter the markup in accordance to that, this includes changing the parent term link from href="#" to href="[wpv-taxonomy-url]" (I just don't have that part marked up yet).

#2642591

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Do you mean that if the parent term does not have any child you do not want to display the "View All" term link?

Can you please share admin access details and tell me what exactly you want to hide and when and I'm happy to help you. You can share details with what term you want to display "view ALL" link and when you want to hide it or what are the conditions when you want to show/hide "View All" link.

*** 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 have set the next reply to private which means only you and I have access to it.

#2642993

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please check now: enlace oculto

As you can see with the following view:
=> enlace oculto

I've added the shortcode attribute and also added the term url to as you can see the view's loop its adjusted as give under and removed the conditional shortcode:

<wpv-loop>
              	<li class="product-cat-list-item">
              	<a href="[wpv-taxonomy-url]" class="product-cat-has-children" aria-haspopup="true" aria-controls="[wpv-taxonomy-slug]-list">[wpv-taxonomy-title]</a>
              	    <ul id="[wpv-taxonomy-slug]-list" class="product-cat-children-list">
                        [wpv-view name="product-categories-landing-grandchildren" term_url="[wpv-taxonomy-url]" term_title="[wpv-taxonomy-title]"]
                        
                    </ul>
              	
          	</li>
		

Then with the "product-categories-landing-grandchildren" view I've adjusted the output of view as given under where I've added the "View All" link outside the view's loop but within the "[wpv-items-found]" section.
=> enlace oculto

<li class="product-cat-list-item view-all">
              <a href="[wpv-attribute name='term_url']">View All [wpv-attribute name='term_title']</a>
         </li>

Can you please confirm it works as expected now.

#2643379

Are those attributes standard features of Toolset's shortcodes? Could I conceivably add term_slug="" if I wanted to pull in the parent term's slug in the nested view like you did with the url and title?

#2643585

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Are those attributes standard features of Toolset's shortcodes? Could I conceivably add term_slug="" if I wanted to pull in the parent term's slug in the nested view like you did with the url and title?
==>
Those are shortcode arguments and you can access those shortcode argument you passed using the shortcode [wpv-attribute name='term_url']. You can pass any number of arguments as you want and catch the value of same using the shortcode [wpv-attribute].

More info:
- https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute

#2644177

Oh wow, that's a neat feature. It appears to have worked for my application. Thank you for your assistance!