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