Hi!
I have a shopping page - I have a custom taxonomy type called products, a child of this is brands and further children are the specific brand names. I would like to Use the [wpv-post-taxonomy] to show only the Brand name for any given product and not have it also say "brands." Is this possible?
Thanks!!
Hi jamesG-3,
Could you describe more details for the question?
Are we talking about this case:
posts 1
--terms under products taxonomy: Brand a, Brand b
posts 2
-- none terms under products taxonomy
You are going to display as this:
posts 1, brands: Brand a, Brand b
posts 2, brands:
Thanks for the reply. The exactly as you stated. Where it falls down now is the taxonomy is as follows under the product categories custom taxonomy:
Brand
brand 1
brand 2
Men's Clothing
shorts
jeans
etc...
I would like then only to display in the main view
"Product Name"
"Brand 1"
And not display anything except a child of brands. Does that make sense? Presently it would display:
"Product Name"
"Brand 1, Jeans"
Dear James,
Luo is unavailable to handle this ticket for now, I will take care for you. Our native shortcode doesn't cover this needed, you will need to write a new one. I have one for you, put it in functions.php of the current theme:
function show_child_cat_func( $atts ) {
extract( shortcode_atts( array(
'taxonomy' => ''
), $atts ) );
$args=array(
'orderby' => 'id',
'order' => 'ASC',
'taxonomy' => $taxonomy,
'hide_empty' => 0,
);
$categories=get_categories($args);
echo '<ul>';
foreach($categories as $category) {
if($category->parent!=0)
{
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . $category->name. '" ' . '>' . $category->name.'</a> </li> ';
}
}
echo '</ul>';
}
add_shortcode( 'show_child_cat', 'show_child_cat_func' );
You can style this as you want, I used
to wrap them. You must call this shortcode like this: [show_child_cat taxonomy = "products"]
Please let me know if you are satisfied with my answer and if I can help you with any other related question.
Thank you so much for the time and effort with this!
To clarify, the shortcake to bring up all product categories is: [wpv-post-taxonomy type="shop-categories" separator=" " format="link" show="name" order="asc"]
Brands is one of the categories and it has children. It is only the children of brands I want showing. I tried [show_child_cat taxonomy = "products"] and [show_child_cat taxonomy = "brands"] and neither returned a result. What would you suggest?
Thanks again!
Dear James,
I would like to see your site to understand if this shortcode will works well for you. Can you provide credentials to your site? The private area is enabled, please fill required fields.
Dear James,
Please use the private area to provide these kind of information, I've just deleted the other reply of you. Also fill the website URL field, I will need it as well.
They are now in the private section, thanks!
Dear James,
I've just created an example page: hidden link
I used my shortcode to display child taxonomies of "category": [show_child_cat taxonomy = "category"]
It is working fine. What is the problem?
Hi there - the list I can show fine. What I am looking to do is to have a shortcode that only displays the child taxonomies selected by the current post. What I mean by this is presently on a product page, as someone adds a project they choose the brand, and they also choose tags. I would like the displayed page to show the brand name that was chosen, but not also show the word "brands" which would be the parent taxonomy. Thanks!
Dear James,
I see, so the custom shortcode will be another one. Try this below:
function show_child_cat_func( $atts ) {
extract( shortcode_atts( array(
'taxonomy' => ''
), $atts ) );
$args=array(
'orderby' => 'id',
'order' => 'ASC',
'hide_empty' => 0,
);
$categories=wp_get_post_terms(get_the_ID(), $taxonomy, $args);
echo '<ul>';
foreach($categories as $category) {
if($category->parent!=0)
{
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . $category->name. '" ' . '>' . $category->name.'</a> </li> ';
}
}
echo '</ul>';
}
add_shortcode( 'show_child_cat', 'show_child_cat_func' );
Call the shortcode in the same way and let me know if it solves your issue.
Hi there - thanks again!
I think I still may be missing something? It still brings back no response to me using the shortcode [show_child_cat] or [show_child_cat_func] - thanks so much for working through this
Dear James,
I've just fixed it for you. The right code should be:
function show_child_cat_func( $atts ) {
extract( shortcode_atts( array(
'taxonomy' => ''
), $atts ) );
$args=array(
'orderby' => 'id',
'order' => 'ASC',
'hide_empty' => 0,
);
$categories=wp_get_post_terms(get_the_ID(), $taxonomy);
$content = '';
$content .= '<ul>';
foreach($categories as $category) {
if($category->parent!=0)
{
$content .= '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . $category->name. '" ' . '>' . $category->name.'</a> </li> ';
}
}
$content .= '</ul>';
return $content;
}
add_shortcode( 'show_child_cat', 'show_child_cat_func' );
Sorry for my mistake, the correct is "return" instead of "echo".
Please let me know if you are satisfied with my answer and if I can help you with any other related question.
Thank you for further working through this. It is still not returning a response however. [show_child_cat] is coming up blank and [show_child_cat_func] brings up simply the text "[show_child_cat_func]" as written.
Again, thanks for the support!
Dear James,
It is working fine for me, please look: hidden link
I've just used - [show_child_cat taxonomy="category"] - it is displaying only child categories of this product. If it is not what you want, please explain it a bit more, I'm not sure if understand properly what you want to achieve.