-
-
Save kumarrahul-rkv/2aebe5f7cc95a10ef2d10dda9ed5c743 to your computer and use it in GitHub Desktop.
Add classes wp_list_categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//themes functions.php | |
class MyWalker extends Walker_Category { | |
function start_el(&$output, $category, $depth, $args) { | |
extract($args); | |
$cat_name = esc_attr( $category->name ); | |
$link = '<a href="%1$s" rel="%2$s">%3$s</a>'; | |
$link = sprintf($link | |
, esc_attr( get_term_link($category) ) | |
, $category->slug | |
, $cat_name | |
); | |
$check_mago = count( get_ancestors( $category->term_id, 'category' ) ); | |
if($check_mago == 2 and $category->category_parent > 0 ){ | |
$class = 'mago'; | |
} | |
if($check_mago == 1 and $category->category_parent > 0 ){ | |
$class = 'kodomo'; | |
} | |
if($category->category_parent == 0){ | |
$class = 'oya'; | |
} | |
$output .= '<li class="'.$class.'">'.$link; | |
} | |
} | |
//template | |
<?php | |
$MyWalker = new MyWalker(); | |
$args = array('walker' => $MyWalker); | |
?> | |
<ul> | |
<?php | |
wp_list_categories($args); | |
?> | |
</ul> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment