Skip Navigation

[Resolved] Display list of Post links and breadcrumbs to parent, grandparent, and great-grandparent posts

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

Problem: I would like to display a list of Listing post links. On the same page, I would like to display breadcrumbs showing links to the parent, grandparent, and great-grandparent posts from different custom post types.

Solution: Use a nested Content Template structure to access grandparent and great-grandparent post information from within the Listing post. We have a detailed guide that describes how to access grandparent posts (see link below).

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"]

Relevant Documentation:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/

This support ticket is created 6 years, 5 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 11 replies, has 2 voices.

Last updated by Ed 6 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#907890

Ed

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])

#908433

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.

#908446

Ed

Thanks, Christian! This may take me a little while. I'll respond either way.

I appreciate your time!

#908475

Ed

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.

#908525

Ed
Directory - San Angelo, Texas.png
no-items-found.png

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?

#908799

Ed

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).

#908968

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?

#909313

Ed
Breadcrumbs.png

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!

#909418

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?

#909816

Ed

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.

#910696

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"]
#911065

Ed

Thanks, Christian. I'll see if I can implement this. I appreciate all your help!