Good afternoon , this is the problem : I have an asside menu , this menu has 4 categories and each of this categories has many subcategories , What I am trying to do is that when I am on the page of a subcategory I give a class to a
on the left menu , a class of active so the category of the subcategory I am in stays opens . Whole code here : https://pastebin.com/Q09eE9nB$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => 52,
'hide_empty' => 0
));
<?php if( $categories ): ?>
<ul class="main-categ">
<?php foreach ( $categories as $kCat => $vCat ): ?>
<li class="main-item <?php echo get_category_by_slug( $categories ) == $subCategories ? 'active' : ''; ?>"><?php
$subCategories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => $vCat->cat_ID,
'hide_empty' => 0
));?>
<a class="main-link" href="#<?php echo $vCat->slug; ?>" data-cat="<?php echo $vCat->slug; ?>"><?php echo $vCat->name; ?></a>
<?php if( $subCategories ): ?>
<ul class="subcateg">
<?php foreach ( $subCategories as $kSub => $vSub ): ?>
<li><a href="<?php echo esc_url( get_category_link( $vSub->cat_ID ) ); ?>"><i class="fa fa-angle-double-right"></i> <?php echo $vSub->name; ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>