sorry the above code is this :
<?php
$categories = get_categories();
foreach ($categories as $cat) {
echo '<li><a href="'.get_option('home').'/'.get_option('category_base').'/'.$cat->category_nicename.'/"><span>'.$cat->cat_name.'</span></a></li>';
}
?>
[moderated–bump removed. Please refrain from bumping as per Forum Rules]
have you tried using get_category_link?
<?php
$categories = get_categories();
foreach ($categories as $cat) {
echo '<li><a href="'.get_category_link( $cat->cat_ID ).'/"><span>'.$cat->cat_name.'</span></a></li>';
}
?>
thanx man , it works , u made my day , but can u please tell me how can have the category count after the name in this code?
you should be able to do $cat->category_count
to get the count. see the get_categories examples or the category member variables for more information.
e.g.
<?php
$categories = get_categories();
foreach ($categories as $cat) {
echo '<li><a href="'.get_category_link( $cat->cat_ID ).'/"><span>'.$cat->cat_name.' ('. $cat->category_count .')'</span></a></li>';
}
?>
this is exactly what i wanted..really thanx
Great! Just what I was searching for. But for an added layer of complexity, how do you make this work with the Show Active Category plugin? Here’s the original code for this plugin:
function show_active_category($text) {
global $post;
if( is_single() || is_category() ) {
$categories = wp_get_post_categories($post->ID);
foreach( $categories as $catid ) {
$cat = get_category($catid);
if(preg_match('#>' . $cat->name . '</a>#', $text)) {
$text = str_replace('>' . $cat->name . '</a>', ' class="active-cat">' . $cat->name . '</a>', $text);
}
}
}
return $text;
}
add_filter('wp_list_categories', 'show_active_category');
All this does is add a “active-cat” class to the anchor tag relevant to the single page’s category. As it stands it doesn’t work. I also tried changing the $categories variable names so they don’t conflict, and changing the filtered function to that of get_categories(), since this is the actual function used to list the categories, not wp_list_categories().
Any englightenment would be very helpful.
thanks!