Skip Navigation

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

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

Problem:

I have a child archive page which I want to display the parent term's title with link.

Solution:

There isn't such kind of built-in feature within Toolset plugins, in my opinion, you can use the custom shortcode, see solution in below similar thread:

https://toolset.com/forums/topic/display-parent-taxonomy-title-on-custom-wordpress-archive-page/#post-1844157

Relevant Documentation:

This support ticket is created 2 years, 9 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
- 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by graemeH-3 2 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#2325743

I have a child archive page which I want to display the parent term's title with link.

For example, the set up is states with their cities as sub terms.

On the city page, I want to display a link to its parent archive page,

so like, on my city page, /florida/miami, I want to display the link to the /florida archive page with the text "Florida" .
___________________________________________________________________________
I found this support post and code,

https://toolset.com/forums/topic/display-parent-taxonomy-title-on-custom-wordpress-archive-page/#post-1844157

The post is a year or two out of date, and I know Toolset has been making so many new changes and improvements.

I just wanted to check that this is the best way to accomplish this currently?

___________________________________________________________________________
I added a second edition of this same code to fetch the parent terms slug, which seems to have worked.

Seems kind of extra to do all this coding just for a link to a taxonomy's parent term page, like it seems like maybe I'm just missing the shortcode? But I cant seem to find any shortcodes for it.

Please just let me know if there is a better way I should be doing this, even for example, how I would fetch the URL of the parent term, instead I'm fetching the slug, and adding the shortcode to the end of my URL to make it work lol.

Here's the second php code I used in Toolset custom codes I made to fetch the slug, which seems to work, copied from Jamal's work in the other post,
___________________________________________________________________________
add_shortcode('top-most-parent-slug', 'jts_get_term_slug_top_most_parent');

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

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

return $termslug->slug;
}
___________________________________________________________________________

Then to get the link I'm using, ".com/laundromats-near-me/[top-most-parent-slug]" using that as the ahref, and then as the text, "[top-most-parent]" , like from Jamal's original code. (ex. /laundromats-near-me/florida, and "Florida")

Seems a little clunky but it does appear to be working.

Thanks for any thoughts and insights, your help has been invaluable 🙂

G

#2325783

Hello,

You are right, there isn't such kind of built-in feature within Toolset plugins, in my opinion, you can use the custom shortcode you mentioned above. It should work in future version of Toolset plugins too.

#2326653

Ok great thank you 🙂