I have a products categories' navigation menu printing out like this
<?php
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
);
$product_categories = get_terms( 'product_cat', $cat_args );
if( !empty($product_categories) ){
echo '<ul>';
foreach ($product_categories as $key => $category) {
echo '<li class="menuNav">';
echo '<a href="/'.$category->slug.'_product_sale/" >';
echo get_term_meta($category->term_id, 'cat_one', true);
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
?>
Now I want to compare their href attributes and current page's slug, and if they match, I want to give that anchor tag a class name 'current'. So that I can style that one anchor tag to show which category is selected right now.
I found out I can grab current page's slug like this
$current_page_slug = $post->post_name;
I can't figure out how to grab href attributes one by one and compare with the slug. Could I get any help?