Skip Navigation

[Resolved] Help creating a nested view of taxonomy terms to display on archive page sidebar

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

Problem: I would like to create a hierarchical menu of taxonomy term links.

Solution: Use multiple nested Views of this taxonomy. Filter these Views by term ID or term parent, and output the term links and/or another nested View in each Loop.
Use the following custom shortcode to get the ID of an ancestor term at a specific level of hierarchy:

function n_level_term_id_func($atts) {
  $a = shortcode_atts( array(
      'n' => '0'
  ), $atts );
  $id = 0;
  $current_taxonomy = isset(get_queried_object()->taxonomy) ? get_queried_object()->taxonomy : null;
  if( $current_taxonomy == 'book-tax' ) {
    $ancestors = get_ancestors( get_queried_object()->term_id, $current_taxonomy );
    $count = count( $ancestors );
    $id = isset( $ancestors[ $count - $a['n'] ] ) ? $ancestors[ $count - $a['n']] : get_queried_object()->term_id;
  }
  return $id;
}
add_shortcode("n-level-term-id", "n_level_term_id_func");

Register this shortcode in third-party shortcode arguments, then you can use it as a term ID filter for any View:

[wpv-view name="your-view-slug" terms="[n-level-term-id n='2']"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 5 years, 7 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 19 replies, has 4 voices.

Last updated by liatG 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1103746
New View setup - 2.png
New View setup - 1.png
Widget Setup.png
Sidebar Widget after all steps.png

Thank you so much!

I went to check how it looked (on page hidden link), and right now the sidebar widget isn't displaying anything.

I have included screenshots of the widget HTML with the view slug inserted, plus the setup of the view itself.

I followed all your directions to the best of my knowledge. I used "no order" for the sort order just in case a lack of data in the sort field was causing it to show no results, but that didn't change anything.

Thanks for your help.
Liat

#1104612

Your code looks good, something was wrong with the connection between the Main Chapter Terms View Loop and its Loop Template. I disconnected the template from the Loop and now it seems to be working correctly.

#1104756
Main Chapter Terms loop setup.png
Desired Sidebar Contents.png
Current Sidebar.png

Thanks so much. I'm sorry for all the back-and-forth, but I'm missing one last piece.

I've lost the Terms Within Each Chapter - the sidebar is just showing the highest-level terms. See screenshot: current sidebar.

I'm hoping we can get it so that it shows the terms within each chapter as well: See screenshot: desired sidebar contents.

I didn't change anything in the Main Chapter Terms view - it seems to include the terms within each chapter, like before, but they don't show up in the sidebar.

I swear this is the last step to having a working sidebar to navigate this big class. Thank you so much for your help.

Liat

#1104826
Screen Shot 2018-09-10 at 4.26.08 PM.png

Okay I see these Views do not work well with embedded Content Templates. Not sure exactly why right now, but it could be because of how they are nested. If you need to use the Loop Wizard again in these Views, uncheck the box "Use a Content Template to group the fields in this Loop" shown in the image here. Build your loops directly in the Loop editor, rather than using a separate Content Template in the Loop. If this becomes a larger problem, we can investigate in more detail, but for now your term View loops are simple enough that you won't need to repeat a lot of code in the Loop Editor.

#1104901
It worked.png

It worked!! I didn't think I'd be able to follow your directions right, but I did!

I just copied the existing HTML, re-did the Loop Wizard unclicking the Content Template, and pasted the same HTML back in the loop where it was before. It worked perfectly!

Thank you so much.

Uploading a screenshot just to show the final result.

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