php - How to add active state of category menu in wordpress? -



php - How to add active state of category menu in wordpress? -

i create template category menu. when click "category", based on category reload page shows post in category. need create category menu active. how do?

category-menu.php

<div class="row text-center" > <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12"> <?php $menu_item=wp_get_nav_menu_items( 'category menus', $args ); foreach ($menu_item $menu) { ?> <div class="col-lg-3 col-sm-12 col-xs-12 col-md-3 menu-padding"> <div class="blog-menu-items cat-menu-color"> <a href="<?php echo $menu->url; ?>"> <?php echo $menu->title; ?> </a> </div> </div> <?php } ?> </div> </div>

category.php

<?php get_template_part( 'category', 'menus' ); ?> <?php $cat_title = strtoupper(get_cat_name($category_id)); ?> <div class="row" style="padding-top:5%;"> <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12"> <a href="<?php echo home_url() ?>" class="back-to-blog"> <i class="icon-chevron-left"></i> <?php echo __( 'back home', 'tiny_theme') ?> </a> </div> </div> <div class="row popular-posts"> <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12"> <div class="col-lg-8 col-sm-6 col-xs-6 col-md-8 popular-posts-header pull-left"> <h4>posts on <?php echo $cat_title ?></h4> </div> <?php if ($query1->max_num_pages > 1) { ?> <div class="col-lg-4 col-sm-6 col-xs-6 col-md-4 pull-right" id="popular-post-pager" > <?php echo paginate_links( $pag_args1 );?> </div> <?php } ?> </div> <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12"> <?php if ($query1->have_posts()) { while ($query1->have_posts()) { $query1->the_post(); ?> <h4 style="padding-top:5px;"> <a href="<?php the_permalink(); ?>"><?php echo the_title(); ?></a> </h4> <p> <?php the_excerpt(10); ?></p> <?php } } wp_reset_query(); ?> </div> </div>

you can seek comparaison between current category id , object_id holds id of object link in relation with, this

(not tested)

<div class="row text-center" > <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12"> <?php global $post; $menu_item=wp_get_nav_menu_items( 'category menus', $args ); foreach ($menu_item $menu) { $currentclass = ''; if($post->id == $menu->object_id) $currentclass = 'current-menu-item'; ?> <div class="col-lg-3 col-sm-12 col-xs-12 col-md-3 menu-padding"> <div class="blog-menu-items cat-menu-color"> <a class="<?php echo $currentclass; ?>" href="<?php echo $menu->url; ?>"> <?php echo $menu->title; ?> </a> </div> </div> <?php } ?> </div> </div>

php wordpress

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -