Skip Navigation

[Resolved] Creating a conditional view based on child CPT

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

Problem:
How to display Custom Taxonomy and its posts in Tabs? Also hide the Tabs which do not have any content inside it?

Solution:
Solution here with screenshots: https://toolset.com/forums/topic/creating-a-conditional-view-based-on-child-cpt/#post-558689

This support ticket is created 7 years, 3 months 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

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

This topic contains 5 replies, has 2 voices.

Last updated by Noman 7 years, 3 months ago.

Assisted by: Noman.

Author
Posts
#558596

Tell us what you are trying to do?
I have a CPT called 'credits' and this has a taxonomy associated with it - 'credit types'

I have read this post and also others on tabs

https://toolset.com/forums/topic/custom-post-type-in-tab/#post-266210

What I want to
is to display tabs. Each TAB TITLE to be a 'credit types' i.e. like a category title if you were using normal posts.

In the TAB CONTENT I want to show a list of CPT 'credits' that belong to that category and some custom fields for each one.

But I only want to show the tab if there is posts in the 'credit type' i.e. if posts exist and have the 'credit type' taxonomy.

Is there any documentation that you are following?

https://toolset.com/forums/topic/show-results-from-1-category-on-page/

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/

Is there a similar example that we can see?

What is the link to your site?
Working on a local server (Macbook) but can move to a test site if needed.

#558689

Noman
Supporter

Languages: English (English )

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

4.png
View 1.png
View 2.png
View 3.png
Hide empty terms.png

Hi Gary,

Thank you for contacting Toolset support. So basically you are trying to:
- List Posts and group them by Taxonomy terms / categories.
- Then show them in Tabs style, where each tab title will be the name of Category / taxonomy term.
- And in that, hide all taxonomy terms that have No posts.

The best approach to do that is by Creating 3 Views -- 1st will have Tabs and Taxonomy names, 2nd and 3rd will be nested Views to display posts based on particular taxonomy:

1. Create a Taxonomy View to apply Tabs using html / bootstrap -- screenshot attached View 1.

2. Create Nested Views as explained in this doc (Section: Taxonomy View with a Post View for a Child): https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

==> Parent View will be a Taxonomy View -- screenshot attached View 2.
==> Child View will be a Posts View -- screenshot attached View 3.

3. To hide empty Taxonomy terms, we have an option in Taxonomy View -- please see attached screenshot.

4. Then insert 1st and 2nd View into the page -- screenshot attached 4.png.

This will give you the desired results. Thank you

#558702

Noman
Supporter

Languages: English (English )

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

Note: I have just edited above response, added some screenshots and clarify it further so it easy to understand.

#558734

Hi Noman,
thanks for your help on this. I just need to clarify the outcome.
So to recap your points:
- List Posts and group them by Taxonomy terms / categories.
- Then show them in Tabs style, where each tab title will be the name of Category / taxonomy term.
- CHANGE - Hide a tab and the tab content if there are no posts with the specified taxonomy terms.

#558748

Hi Noman, I've got it to work. You did all the 'heavy lifting' though and gave me the solution. It works perfectly.

Thank you so much for your help - amazing.

Gary

#558753

Noman
Supporter

Languages: English (English )

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

Great to hear that issue is resolved now 🙂 We are happy to help you, have a great day.

Thanks for the feedback.