Skip Navigation

[Résolu] Taxonomy Term Specific Content Template

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

Problem:

The issue here is that the customer wanted to use a different content template for each of his Taxonomy Terms.

Solution:

The solution to this is by using the has_term function and our [wpv-conditional] shortcode.

For example.

[wpv-conditional if="( has_term('Chinese', 'foreign-language', null) eq '1' )" ]
  
Content template 1 
[/wpv-conditional]
 
[wpv-conditional if="( has_term('Japanese', 'foreign-language', null) eq '1' )" ]
  
Content template 2
[/wpv-conditional]
 
[wpv-conditional if="( has_term('French', 'foreign-language', null) eq '1' )" ]
  
Content template 3
[/wpv-conditional]

This way for each of the taxonomy terms you are able to use a different content template to depict how they are displayed.

Relevant Documentation:

For more information on this please take a look at the link below.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/

This support ticket is created Il y a 8 années. 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Marqué : 

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

Last updated by DavidAlexander Il y a 7 années et 12 mois.

Assisted by: Shane.

Auteur
Publications
#378079

I am using WooCommerce and want

1) All products in "Reports" product category to use one specific woocommerce content template with views

2) All products in "Subscriptions" product category to use a different specific content template.

How do I achieve this? I can't seem to find a setting.

#378140

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for contacting our support forum.

This is only possible by going through and manually assigning the posts of these categories to the respective content template.

Our content template settings cannot do this automatically unfortunately 🙁

Please let me know if this helps.
Thanks,
Shane

#378165

Ah, okay, I thought it was possible, problem is I am importing 1000's of products to different categories in some instances, and every category needs to have a unique single product template as each category of products includes completely different kinds of products.

Is there a way I can set each product category archive to show a unique content template? or that also not possible? Just trying to find a way to make views do what I need and doesn't seem to have some options I thought would be standard and required by lots of sites. I mean the whole benefit of having the flexible content templates is to be able to use them across groups of products or individual ones but not being able to edit this without doing 1 at a time would take days.

#378171

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thinking on this a bit it is actually possible to have a different setup for each product under a different category given that the products don't have overlapping categories.

If this is so then we can use the wpv-conditional statement to display the product differently based on the category.

Please let me know if the categories don't overlap for products.

Thanks,
Shane

#378175

That assumption is correct Shane. The way it works and I want the following

Subscriptions Category > All Products in here to use Content Template A

Reports Category > All Products in here to use Content Template B
- Sub Category of Reports > As above, to use the Content Template B
- Sub Category of Reports > As above, to use the Content Template B
- Sub Category of Reports > As above, to use the Content Template B

So while we have sub categories you are right, there is no overlap, the two tiers are 1) subscriptions and 2) Reports, both contain different requirements and so need a completely different output/layout.

So how would I modify what I had using the wpv-conditional?

Thanks Shane, appreciate your assistance. I also have the following support ticket open that I am confused by when using these shortcodes within my content template to decide where to output certain criteria.

If you go to this link you will see another approach I was trying also.

https://toolset.com/forums/topic/views-conditional-shortcode-has-term-not-working-with-woocommerce-for-me/

#378946

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

In this case i'm thinking you can create the multiple content templates and then switch between them using the wpv-conditional shortcode.

For example.

[wpv-conditional if="( has_term('Chinese', 'foreign-language', null) eq '1' )" ]
 
Content template 1 
[/wpv-conditional]

[wpv-conditional if="( has_term('Japanese', 'foreign-language', null) eq '1' )" ]
 
Content template 2
[/wpv-conditional]

[wpv-conditional if="( has_term('French', 'foreign-language', null) eq '1' )" ]
 
Content template 3
[/wpv-conditional]

This way for each of the taxonomy terms you are able to use a different content template to depict how they are displayed.

Please let me know if this helps.

Thanks.
Shane

#379016

Yes I will try this but I can't get that conditional to work for me at the moment. I am discussing this issue on another thread but will jump back to this one once the basic usage of has_term is resolved. At the moment I can't get that to detect my product_cat in wordpress for some reason.

Thanks

#379238

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

I believe this isn't working because the has_term custom function may not be registered for use the in the wpv-conditional statement.

Before a WordPress core function can be used by Views, you must first register it:

1. Open your Conditional Output GUI
2. Switch to the Settings tab (on the left side)
3. In the “Registered functions” section type in the has_term and press +Add button
4. Close the window with the Close button
Now you can use the has_term in your condition to check if a post that is currently displayed has a specific term assign.

Please let me know if this helps.

Thanks,
Shane

#379246
Capture.PNG

Please see attachment. I tried this last week. Seems I am going around in circles. Maybe Toolset isn't the right tool to do this afterall? Is there any alternatives you know of I can try? Toolset hardly works and I just get the same advice over and over. Does support not login and help if something doesn't work after several attempts?

I am a week behind on my project now and the client is about to pull the plug.

#379249

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Yes we actually do log in.

What you can do is to provide me with the credentials and i'll take a look for you.

The private fields have been enabled.

Please let me know where to look.

Thanks,
Shane

#379263

Did you get the information I sent? When you do it private I am never sure where to check to see it has been received.

Thanks Shane, appreciate you looking into it for me.

#379280

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Yes I have received the info in the private fields.

Thanks

#379286

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

It seems the issue was that you were not using the correct name for the taxonomy term being checked. You were using Report when it should've been Reports.

Either way I got it to work and load a content template for Reports and added that to a conditional as you can see here.

hidden link

Notice that the link below loads a content template
hidden link

And the one below doesnt.
hidden link

This is because a content template for the one above hasn't been created as yet and it does not have the Report taxonomy Term attached to it.

Please let me know if this help.

Thanks,
Shane

#379321

Wow, now I feel like a total noob! Thank you very much Shane, nicely spotted. I think at some point I must have been testing "Reports" plural but perhaps in the process of changing different shortcodes etc I must have made that singular so thank you for resolving.

Also VERY nice solution to my issue with loading different templates entirely for single posts residing within different categories. If that process isn't in the docs I give you a big vote to put it in as it really opens the playing field with using Views and WooCommerce and having the one template for products actually recycle and load other content templates is a genius way to solve this that didn't seem as obvious from my research but now makes total sense.

Thanks again Shane.

#379329
Capturexx.PNG

One quick add on, how did you do that second step.

When I tried to replicate on a different install I created the first template and that works fine. Then I created the second template as the conditional template to output the [wpv-post-body view_template="general-product-template"] shortcode (making sure I had created this with the same slug) and instead of outputting it it shows the attached screenshot outputting the actual shortcodes as set in the template.

So I think my point here is, how can one content template call another content template to achieve this? Do they not both need to be somehow assigned to the product still?

I am looking at all options / settings on the apple example site where you have these shortcodes working fine using one template to call in another.

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