Skip Navigation

[Resolved] Display content conditionally for category

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

Problem:

Display different contents on post taxonomy terms.

Solution:

You can use Toolset conditional block to check the post term value, and display different contents.

Relevant Documentation:

https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

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

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 – 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/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by lesleyA 2 years ago.

Assisted by: Luo Yang.

Author
Posts
#2328849

Tell us what you are trying to do?
I have a CPT called suppliers. Some of my suppliers are experts. I have created a category: 'Experts'
I would like to show on the posts for experts, a corner flash that tells visitors that they are viewing an 'expert'.
I think I need to do something in settings with Custom Code and Front-end Content, but I've become confused!

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/displaying-custom-functions-with-views-and-using-them-in-conditional-logic/#:~:text=To%20register%2C%20visit%20the%20Toolset,name%20in%20the%20relevant%20box.

Is there a similar example that we can see?

What is the link to your site?

#2329283

Hello,

It does not custom codes, you can use [wpv-conditional] shortcode to check if current post has specific term, then output the "corner flash" with HTML codes, for example, see the solution of below similar thread:
https://toolset.com/forums/topic/setting-up-conditional-css-depending-on-taxonomy/

More help:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

#2329363
Screen Shot 2022-03-29 at 10.02.52.png
Screen Shot 2022-03-29 at 10.02.13.png

Hello Luo,

Thank you for responding to my query. I think I understand the principle of what I need to do, but it's the how I achieve it. (I feel I might learn something significant today!)

I followed the video which was very helpful and think I will be able to achieve what I need once I have resolved a problem.

When I edit conditions, I don't have "post taxonomies as an option". I have attached a screen grab to show you.

Please can you tell me how to add post taxonomies to the list?

#2329413
source.jpg

I have tried the Toolset conditional block in my localhost with a fresh WP installation + the latest version of Toolset plugin, I can see the the post taxonomies option correctly, see my screenshot source.JPG

If you need more assistance for it, please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URL, I can setup a demo for you

#2329823
conditions.jpg

Thanks for the details, I can login into your website, since you did not point out the problem page URL, I assume we are talking about the content template for single "Suppliers" post: Template for Suppliers
hidden link
I have tried these in your website:
1) Edit above content template, add a Toolset conditional block, I can setup the conditions correctly, see my screenshot conditions.JPG

2) But I can not save the content template after any change, even after add a paragraph block, and I see lots of JS errors in your website, please check the compatibility issues in your website, by these:
a) deactivate all other plugins, and switch to WordPress default theme 2021, and test again
b) if the problem is fixed, activate other plugins/theme one by one, try to locate the problem plugin/theme

#2329985

Dear Luo

I apologise for forgetting to send you the link. I think in my anxiety and haste to find out what was wrong I forgot it. But you went to the correct page.

Yesterday, I noticed something similar. Sometimes I was able to make a conditional, but not able to save the template. I worked around by switching to draft and then re-publishing the template. But then, going back it, I'd notice that the conditional statement was incomplete.

I will follow your advice and shut down the plugins to see which ones are causing the problem.

Thank you for your help and advice. I will report back later.

Kind regards

Lesley

#2330013

Dear Luo

I have just now finished switching off all that I can – all plugins and changed the theme to a standard WP theme. I then started up Toolset plugins and checked all templates and pages. They will all update except for the "Template for Suppliers" – the one that you looked at. Pages and posts all seem to work, so can I presume that there is a problem unique to this template?

What course of action would you recommend? Because it is just one template I could rebuild it from scratch and then delete the original. Do you think that might be worth trying?

#2330029

It might be an exception of that content template, you can trash/delete that content template, rebuild one, if the problem persists, please provide detail steps to reproduce the same problem(without other plugins)

#2330109

Thank you Luo. I shall rebuild the template and report back.

Kindest,

Lesley

#2330527

Please update here if you need more assistance for it, thanks

#2330607

Dear Luo

I believe the problem to caused by some CSS. Every time I apply the below CSS to the HTML block the template is corrupted:

<div id="flashyhome"><div class="flashy">BOSS CLUB EXPERT</div></div>

#flashyhome{
position:relative;
}

.flashy{
width: auto;
height: auto;
border-radius: 30px;
background-color: #FA4400;
-ms-transform: rotate(10deg); /* IE 9 */
transform: rotate(10deg);
color: white;
text-align: center;
font-size: 18px;
font-weight: 700;
padding: 5px 15px;
box-shadow: 7px 7px 7px #888888;
position: absolute;
right: -3rem;
top: -2rem;
}

I will have to work out where I am going wrong! But I thought you might be interested!

Kind regards

Lesley

#2330631

Where do you setup those custom CSS codes?

I have tried it in your website:
1) Edit the content template "Template for suppliers 3":
hidden link

2) Within the conditional block, change the codes as below, wrap the custom CSS codes with HTML tag <style>... </style>:

<div id="flashyhome"><div class="flashy">BOSS CLUB EXPERT</div></div>
<style>
#flashyhome{
position:relative;
}

.flashy{
width: auto;
height: auto;
border-radius: 30px;
background-color: #FA4400;
-ms-transform: rotate(10deg); /* IE 9 */
transform: rotate(10deg);
color: white;
text-align: center;
font-size: 18px;
font-weight: 700;
padding: 5px 15px;
box-shadow: 7px 7px 7px #888888;
position: absolute;
right: -3rem;
top: -2rem;
}
</style>

It works fine, I can save the content template correctly, can you confirm it? thanks

#2330997

Thank you Luo!

This certainly works, and I'd not appreciated that I could simply add the style right there with the HTML. I had been adding it in Astra customiser settings.

But now I have a new problem! Although the template is clearly assigned to "Suppliers" it is showing posts from "knowledge posts" when I preview the template. The dropdown "view with" doesn't work either.

However, if I go to a supplier, then the template works.

Have I made another bug? Should I not worry about the above problem?

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/i-have-a-new-question/

#2331263

I assume the original question of this thread is resolved, for other new issue, please check the new thread here:
https://toolset.com/forums/topic/i-have-a-new-question/

#2331885

My issue is resolved now. Thank you!

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