`Let’s say I went to a category page. There is some content on this category page. I would like to show all the child categories of the parent category of this category below the content or under this category page. I would also like to show the description and thumbnail image of the category. How do I do that?
Then if a user goes to a category page from the menu, that category will remain active. The rest of the categories will be blur, inactive or something like that.
UPDATE:
Let’s say it’s a menu. Now all the category items have been added in this menu. Now if anyone clicks on parent or sub-category from here, all the sub-categories of the parent category of that category will be shown. Like the code below. All right.
But when someone clicks on a category from the menu, that category will be highlighted. The rest of the categories will be in blur or something like that. But if you hover the mouse, that blur will no longer exist.
I would have benefited if someone helped. Any ideas?
if( is_product_category() ){
$queried_object = get_queried_object();
$child_terms = get_term_children ( $queried_object->term_id, 'product_cat' );
$based_term = (is_wp_error($child_terms) || empty($child_terms)) ? get_term ( $queried_object->parent, 'product_cat' ) : $queried_object;
printf( '<h2 class="shop__sidebar-heading"><a href="%s?so64231449=true">%s</a></h2>', esc_url(get_term_link($based_term->term_id)), $based_term->name );
$display_terms = get_terms( 'product_cat', array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'parent' => $based_term->term_id,
) );
if( !empty( $display_terms ) && !is_wp_error( $display_terms ) ){
echo '';
foreach( $display_terms as $display_term ){
$thumbnail_id = get_term_meta ($display_term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url( $thumbnail_id );
printf(
'<div class="col-md-3">
<div class="content-inner">
<h6%s><a href="%s">%s</a></h6>
<img src="%s" alt="" />
</div>
</div>',
($display_term->term_id == $queried_object->term_id) ? ' class="active"' : '',
esc_url(get_term_link($display_term->term_id)),
$display_term->name,
$image,
);
}
echo '';
}
}
2
Answers
Add active class on first category box using counter variable.
Add class on
category-box
on hover called ‘active’ and based on do CSS.