Skip Navigation

[Resolved] Display parent taxonomy title on custom wordpress archive page

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

Problem:
The user would like to display the topmost parent taxonomy term in its child terms archives.

Solution:
This will need a custom shortcode, check this reply https://toolset.com/forums/topic/display-parent-taxonomy-title-on-custom-wordpress-archive-page/#post-1844157

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

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: Africa/Casablanca (GMT+01:00)

This topic contains 5 replies, has 2 voices.

Last updated by kayeL 4 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1842605
截圖 2020-11-13 上午3.14.32.png

I have a custom taxonomy called "feature" which setup like this.
Cat 1
--------Sub 1
--------Sub 2
--------Sub 3
--------Sub 4
Cat 2
--------Sub 5
--------Sub 6

I've created a custom WordPress archive for feature.

Question 1:
How to show parent title which is "Cat 1" when I'm in sub1 archive page (www.mydomain.com/feature/cat1/sub1)?

Question 2:
How to list all sub categories and it's url under the same level?

Please see the image for what I mean. Thanks

#1843503

Hello and thank you for contacting the Toolset support.

Regarding the first question, I'll suggest you try this:
1) Create a content template, for example "parent-infos", in the content, display below shortcode:
[wpv-post-taxonomy type='building']
2) use above content template to display parent category, fore example:
[wpv-post-body view_template="parent-infos" id="$parent-slug"]

For the second question, I'll suggest using another content template and putting a taxonomy view inside of it, the taxonomy view will query the terms who's parent is the current term.

Please note, that the block-based views and content template do not support taxonomies yet. You will need to build this with the legacy shortcodes, or you can build your own shortcodes to get the expected results.
To activate the legacy editor, go to Toolset->Settings->General->Editting Experience.

Read more about the shortcodes here:
- https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy
- https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-body

#1843775
截圖_2020-11-14_上午1_38_55.png

Just let you know that I'm aware the link here.
https://toolset.com/forums/topic/show-parent-category/
But It's just not working. Please see the attached image and provide more details.

I'm editing WordPress archive page for "Feature".
Feature is a custom taxonomy for Product post type which is also a custom post type by toolset.
Feature has hierarchical like this:
Cat 1
--------Sub 1
--------Sub 2
--------Sub 3
--------Sub 4
Cat 2
--------Sub 5
--------Sub 6

When go to the URL hidden link
It means I'm in Sub1 's archive page. And I'd like to display Cat 1 on that archive page which is Sub1 's parent.
How? Is it possible?

#1844157

I run a test locally and I came up with the following custom shortcode that returns the topmost parent. So, if we go to the URL hidden link it will return Cat 1. And if we go to the URL hidden link it will return Cat 1.

add_shortcode('top-most-parent', 'jts_get_term_top_most_parent');

// Determine the top-most parent of a term
function jts_get_term_top_most_parent( $atts ) {
	// get the term and taxonomy
	$term = get_queried_object ();
	$taxonomy = $term->taxonomy;

	// Climb up the hierarchy until we reach a term with parent = '0'
    while ( isset($term->parent) && $term->parent != '0' ) {
        $term_id = $term->parent;
        $term  = get_term( $term_id, $taxonomy);
    }

	return $term->name;
}

Check this screenshot hidden link

However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason, I have to kindly ask you to open a new ticket if you still need assistance with your 2nd question.

#1846221

Thank you, my issue is resolved.

This link is for my question 2.
https://toolset.com/forums/topic/how-to-display-same-level-taxonomies-or-categories-on-archive-page/

#1846225

My issue is resolved now. Thank you!