I'm creating a directory. I have CPTs that belong to hierarchical Listing Categories. I want to display the categories without CPTs, unless that category has no children categories.
For example:
Currently...
Home » Business » Computers & Internet
Computer Sales & Service (category [link])
-Angelo PC (listing)
-Other Computer Business (listing [link])
-Other Computer Business (listing [link])
-Other Computer Business (listing [link])
Website Design & Hosting (category [link])
-San Angelo Web Design (listing [link])
-Other Web Design Business (listing [link])
-Other Web Design Business (listing [link])
-Other Web Design Business (listing [link])
What I would like to show...
Home » Business » Computers & Internet
Computer Sales & Service (category [link])
Website Design & Hosting (category [link])
Then, ONLY when I click on the lowest (category without child categories), I would like to display the listings.
Home » Business » Computers & Internet>>Computer Sales & Service
-Angelo PC (listing [link])
-Other Computer Business (listing [link])
-Other Computer Business (listing [link])
-Other Computer Business (listing [link])
Hi, I assume that "Computers & Internet" is the parent term of "Computer Sales & Service" and "Website Design & Hosting". I also assume that you want this template to apply to all the term archive pages in the taxonomy hierarchy (even above Computers & Internet). If those assumptions are wrong, please let me know. I would set this up with a WordPress Archive and two nested Views - one View of terms filtered by term parent, and one View of posts filtered by term.
- Go to Toolset > WordPress Archives and create a new WordPress Archive for this taxonomy if one does not exist yet. Select this taxonomy in the Loops Selection area.
- In the Loop Output editor, skip the wizard to produce the basic loop structure. There should be nothing in the wpv-loop tags.
- Create a new View of this taxonomy. Add a Query Filter that filters by term parent, where "Parent is the term of the current taxonomy archive page"
- In the Loop Output editor, use the wizard to design how the list will look when the current term has children. For example, you can insert the wpv-taxonomy-link shortcode in the wpv-loop tags to output a link to each child term's archive page.
- Insert the taxonomy View in the WordPress Archive, just after wpv-layout-start.
- Create a new View of Listings, filtered by taxonomy term, where the term is set by the current archive.
- In the Loop Output of this View of Listings, insert a link to each post using the wpv-post-link shortcode.
- Insert this View in the taxonomy View, in the wpv-items-not-found block. This way if no child terms are found the post View will be displayed.
Thanks, Christian! This may take me a little while. I'll respond either way.
I appreciate your time!
Christian,
Do I need to clarify that the categories are set up with subs and subs of subs?
Level1: Municipal
Level 1: Business
-Level 2: Retail
-Level 2: Automotive
-Level 2: Computers & Internet
--Level 3: Computer Sales & Service
--Level 3: Web Design & Hosting
Level 1: Medical
-Level 2: Hospitals
I just want to know that your solution will work with this structure.
OK...so...it isn't really working (the way I want).
Two issues:
1. I want to show all top-level categories on a page (including empty categories, where there are no listings), that users can "drill down" on, but ALL categories (including children) are shown, jumbled together (see Directory - San Angelo, Texas.png).
2. When I get to the bottom level category (archive), no listings are shown (see no-items-found.png).
Is what I want actually possible?
With the way Toolset handles taxonomies, I think I'm going to end up having to use CPTs as "taxonomies" and set up my own "breadcrumbs" (rather than using Yoast's).
Do I need to clarify that the categories are set up with subs and subs of subs?
I understood this and the solution I provided should handle this type of hierarchy.
1. I want to show all top-level categories on a page (including empty categories, where there are no listings), that users can "drill down" on, but ALL categories (including children) are shown, jumbled together (see Directory - San Angelo, Texas.png).
This will require one more View. Duplicate your current View of the taxonomy, and change the Query Filter to test the term parent. The term parent should be "None" to display only the top-level terms. Place this View in a Page to see the top-level directory.
2. When I get to the bottom level category (archive), no listings are shown (see no-items-found.png).
Can you confirm the term is correctly applied to at least one published Listing post?
Can you share all the code in your WordPress Archive's Loop Output editor?
Can you share all the code in your View of Listings Loop Output editor?
Can you take screenshots of the View of Listings view editor screen in wp-admin?
Christian,
I went a different route. I created the Categories as CPTs (Cat Level 1, Cat Level 2, & Cat Level 3).
I have almost everything working the way I want, except the breadcrumbs. Please see the attached image and see if I'll be able to create what I want.
Level 1 is in a relationship with Level 2 ("child") and Level 3 ("child").
Level 2 is in a relationship with Level 1 ("parent") and Level 3 ("child").
Level 3 is in a relationship with Level 1 ("parent") and Level 2 ("parent").
Listing is in a relationship ONLY with Level 3 ("parent").
Breadcrumbs on Listing page (I already have them working on Category pages) should be: Level 1>>Level 2>>Level 3
Will this be possible?
Thank you!
I can help you set up something like this in a Content Template or Template Layout, but Toolset isn't designed to help you modify the breadcrumbs that are generated automatically by a theme or another plugin. Can you clarify - is Level 1 a parent of Level 3, or is Level 1 only a parent of Level 2?
I'm not using another theme or plugin to create the breadcrumbs. I'm using Toolset.
I've added custom fields to determine (hack) which listings will be displayed in which category levels, but that means each listing must be tied to all three levels, in order for the breadcrumbs to display, properly. I was just hoping to avoid that.
Levels 3 is a child of Level 2 and is also a child of Level 1.
but that means each listing must be tied to all three levels, in order for the breadcrumbs to display, properly. I was just hoping to avoid that.
You can avoid this by using a nested Content Template structure to access grandparent and great-grandparent post information from within the Listing post. We have a detailed guide here that describes how to access grandparent posts:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/
To access great-grandparent posts, you need one more Content Template, which will be used as a nested Content Template. It's all about creating changes in context using post IDs and relationships. The following code is an example. Your slugs will be different, but the concept is the same.
In the Listing post or Listing post Content Template:
[wpv-post-body view_template="cat2-ct-slug" id="[wpv-post-id item='@cat3-listing.parent']"] >> [wpv-post-link item="@cat3-listing.parent"] >> [wpv-post-link]
In the Content Template cat2-ct-slug:
[wpv-post-body view_template="cat1-ct-slug" id="[wpv-post-id item='@cat2-cat3.parent']"] >>
[wpv-post-link item="@cat2-cat3.parent"]
In the Content Template cat1-ct-slug:
[wpv-post-link item="@cat1-cat2.parent"]
Thanks, Christian. I'll see if I can implement this. I appreciate all your help!