I have a menu of categories in the wordpress sidebar within the "News" page, I'm using index.php as the main page of posts setting it by "customize" as in the image below, then in the "News" page the menu category-sidebar shows the current-cat class for the selected category, as in the image below, but when I click on the category-related post and enter the post page, the "active" menu category disappears, just like me could it do to activate it? follow the function of wordpress:
if ( ! empty( $args['current_category'] ) ) {
// 'current_category' can be an array, so we use 'get_terms()'.
$_current_terms = get_terms( $category->taxonomy, array(
'include' => $args['current_category'],
'hide_empty' => false,
) );
foreach ( $_current_terms as $_current_term ) {
if ( $category->term_id == $_current_term->term_id ) {
$css_classes[] = 'current-cat';
} elseif ( $category->term_id == $_current_term->parent ) {
$css_classes[] = 'current-cat-parent';
}
while ( $_current_term->parent ) {
if ( $category->term_id == $_current_term->parent ) {
$css_classes[] = 'current-cat-ancestor';
break;
}
$_current_term = get_term( $_current_term->parent, $category->taxonomy );
}
}
}
<main role="main">
<div class="noticias-title">
<div class="container">
<div class="row">
<p class="font-55-45 bebas-neue">Notícias</p>
</div>
</div>
</div>
<div class="noticias-content-container">
<div class="container-fluid" style="padding: 0px;">
<div class="noticias-categorias-container">
<div class="container-fluid" style="width:100%; padding-right:0px;">
<?php get_sidebar(); ?>
</div>
</div>
<div class="noticias-posts-container">
<div class="container-fluid">
<!-- section -->
<section>
<?php get_template_part('loop'); ?>
<?php get_template_part('pagination'); ?>
</section>
<!-- /section -->
</div>
</div>
</div>
</div>
</main>