Add class on current Category item
<div id="sidebar">
<?php
$ args =array (
'orderby ' => 'name ' ,
'order ' => 'ASC '
);
$ categories =get_categories ($ args );
foreach ($ categories as $ category ) {
echo '<div class="bloc-cat" > ' ;
echo '<div id="titre-cat"><h2><a href=" ' . get_category_link ( $ category ->term_id ) . '" title=" ' . sprintf ( __ ( "Voir toutes les entrees %s " ), $ category ->name ) . '" ' . '> ' . $ category ->name .'</a> <h2></div> ' ;
echo '<div id="description-cat"> ' . $ category ->description . '</div> ' ;
echo '</div> ' ;
}
?>
</div>
Add condition to display class
<div id="sidebar">
<?php
$ args = array (
'orderby ' => 'name ' ,
'order ' => 'ASC '
);
$ categories = get_categories ($ args );
$ current_category = is_single () ? get_the_category () : false ;
foreach ($ categories as $ category ) {
echo '<div class="bloc-cat ' . (($ current_category && $ category ->cat_ID == $ current_category [0 ]->cat_ID ) ? ' current-cat ' : '' ) .'" > ' ;
echo '<div id="titre-cat"> ' ;
echo '<h2><a href=" ' . get_category_link ($ category ->term_id ) . '" title=" ' . sprintf (__ ("Voir toutes les entrees %s " ), $ category ->name ) . '" > ' . $ category ->name . '</a><h2> ' ;
echo '</div> ' ;
echo '<div id="description-cat"> ' . $ category ->description . '</div> ' ;
echo '</div> ' ;
}
?>
</div>
<div id="sidebar">
<?php
$ args = array (
'orderby ' => 'name ' ,
'order ' => 'ASC '
);
$ categories = get_categories ($ args );
$ current_category = is_single () ? get_the_category () : false ;
foreach ($ categories as $ category ) {
echo '<div class="bloc-cat ' . (($ current_category && $ category ->cat_ID == $ current_category [0 ]->cat_ID ) ? ' current-cat ' : '' ) .'" > ' ;
echo '<div id="titre-cat- ' . $ category ->term_id . '"> ' ;
echo '<h2><a href=" ' . get_category_link ($ category ->term_id ) . '" title=" ' . sprintf (__ ("Voir toutes les entrees %s " ), $ category ->name ) . '" > ' . $ category ->name . '</a><h2> ' ;
echo '</div> ' ;
echo '<div id="description-cat"> ' . $ category ->description . '</div> ' ;
echo '</div> ' ;
}
?>
</div>