hey,
i have taxonomy called "free tags", with the slug "free-tags".
under this, i have many terms. let say, for example's sake: "wisdom", "ignorance", "stupidity".
archive pages have this URL:
enlace oculto
enlace oculto
enlace oculto
how would i display the parent taxonomy slug (e.g in this case: "free-tags") in the term's archive page? what's the right shortcode?
I need this because I want to create a link within the archive page to a search view. something like:
<a href="<em><u>enlace oculto</u></em> info='slug']&wpv_filter_submit=SUBMIT&wpv_sort_orderby=post_title&wpv_sort_order=asc">
thx!!
Hello,
There isn't such kind of built-in feature within Toolset, it needs custom codes, for example:
1) Add below codes into your theme file functions.php:
add_shortcode('parent_term_info', function($atts, $content){
$atts = shortcode_atts( array(
'tax' => '',
'output' => 'slug'
), $atts );
$res = '';
$termObj = get_queried_object();
if(isset($termObj->parent) && !empty($atts['tax'])){
$parent_term = get_term( $termObj->parent, $atts['tax'], ARRAY_A);
if(isset($parent_term[$atts['output']])){
$res = $parent_term[$atts['output']];
}
}
return $res;
});
2) Dashboard-> Toolset-> Front-end Content, in section "Third-party shortcode arguments", add above shortcode name: parent_term_info
3) Use the shortcode to setup the link, like this:
<a href="<em><u>enlace oculto</u></em> tax="category"]&wpv_filter_submit=SUBMIT&wpv_sort_orderby=post_title&wpv_sort_order=asc">[parent_term_info tax="category" output="name"]</a>
Please replace "category" with your custom taxonomy slug
Hey Luo!
Thanks for the code 🙂
I need the "tax" to be the current archive's parent taxonomy (I'm placing the link in the archive view of ALL taxonomies).
Will that be possible?
Thanks!
Ido
Yes, it is possible, you can change the PHP codes as below:
add_shortcode('parent_term_info', function($atts, $content){
$atts = shortcode_atts( array(
'output' => 'slug'
), $atts );
$res = '';
$termObj = get_queried_object();
if(isset($termObj->parent) && isset($termObj->taxonomy) ){
$parent_term = get_term( $termObj->parent, $termObj->taxonomy, ARRAY_A);
if(isset($parent_term[$atts['output']])){
$res = $parent_term[$atts['output']];
}
}
return $res;
});
And use above shortcode like this:
slug: [parent_term_info output="slug"]
name: [parent_term_info output="name"]
Don't forget step 2)
Dashboard-> Toolset-> Front-end Content, in section "Third-party shortcode arguments", add above shortcode name: parent_term_info
Oh, and also - this link:
<em><u>enlace oculto</u></em>
opens the page and shows the view, but i'm getting all results and they are not filtered by the tag.
Please test as I mentioned above:
slug: [parent_term_info output="slug"]
name: [parent_term_info output="name"]
Make sure they output correct results.
If they do output courrect results, you will need setup the link manually according to your website settings.
If you need more assistance for it please provide a copy of your website, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/
thx, but the archive page comesout blank with the code in it:
<a href="<em><u>enlace oculto</u></em> output='slug']=[wpv-taxonomy-archive info='slug']&wpv_filter_submit=%D7%97%D7%99%D7%A4%D7%95%D7%A9&wpv_sort_orderby=post_title&wpv_sort_order=asc">הצגה על גבי מפה</a>
but I mananged to get this done by using jQuery:
$(".maptag").click(function() {
var url = $(location).attr('href').split('/');
var taxslug = url[url.length-2];
var archiveslug = url[url.length-3]
window.location.href = "<em><u>enlace oculto</u></em>"+archiveslug+"%5B%5D="+taxslug+"&wpv_filter_submit=%D7%97%D7%99%D7%A4%D7%95%D7%A9&&wpv_filter_submit=%D7%97%D7%99%D7%A4%D7%95%D7%A9&wpv_sort_orderby=post_title&wpv_sort_order=asc";
return false;
});