Make Category Icons Lite work with any Suffusion based theme

With the Suffusion theme, the icons are not displayed in front of the title. So to make this theme compatible, go to Category Icons Lite settings to uncheck Posts. Edit the functions.php file in this theme folder to add this line in the suffusion_theme_setup() function :

add_filter( 'suffusion_get_post_title_and_link', 'bm_caticonslite' );

Then add this function at the end of the file : Continue reading

How to hide No categories if there are no subcategories

Someone is using the put_cat_icons tag in order to display his categories and subcategories in archive.php. This presents a sizeable icon for each subcategory of the currently selected category. How to do this :

$cat = get_cat_ID( single_cat_title("", false) );
put_cat_icons( wp_list_categories('hide_empty=1&orderby=name&echo=0&depth=1&title_li=&child_of='.get_cat_ID( single_cat_title("", false) )));

The problem is that when there is no subcategory, “No categories” is displayed. So to hide this, we’ll use another filter this time, named wp_list_categories. Paste the following code in your functions.php file in your theme.

function bm_dont_display_it($content) {
  if (!empty($content)) {
    $content = str_ireplace('<li>' .__( "No categories" ). '</li>', "", $content);
  }
  return $content;
}
add_filter('wp_list_categories','bm_dont_display_it');

How to set a default icon

Suppose you have categories that don’t have yet an icon assigned to. If you want to display a default icon instead of nothing (no icon), here is the code that you must paste in functions.php (in your theme) :

function bm_noicon($content) {
 if (empty($content)) {
   $content = '<img src="http://yourdomain.com/wp-content/uploads/cisco.gif" alt="default icon" />';
 }
 return $content;
}
add_filter('category_icons', 'bm_noicon');

Of course, you need to replace http://yourdomain.com/wp-content/uploads/cisco.gif by your own icon/image URL.

How to modify the category icons through functions.php

I’ve created a filter named category-icons in the plugin. I used that filter to add SEO Friendly Images compatibility.

So, if you want to play with it in order to modify the icons (rollover or other thing), you can do that in functions.php of your theme. You’ll perhaps need some knowledge about parsing stuff, but it’s worth it. And if you write some cool functions, why not share them with us ? 😀

Example (a very simple one) : Continue reading