Make Category Icons Lite work with any Hybrid based theme

There are some Hybrid based themes that don’t work with Category Icons Lite. For example, Ascetica : 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.

Uncheck Posts

Uncheck Posts

Then, in functions.php in Ascetica theme folder, add this line in the function named ascetica_theme_setup (“theme-name_theme_setup” to be generic) : Continue reading

How to use a template tag to display icons with Category Icons Lite

You must have at least v1.0.4. Just copy and paste this code in your template file (index.php, loop.php, etc) :

<?php if (function_exists('get_cat_icon_lite')) echo get_cat_icon_lite();?>

You can also give it the category id. If you want to display the icon for the category id number 3, you’d do that :

<?php echo get_cat_icon_lite(3); ?>

How to get only the icons URL

If you want to get only the icons URL, you need to copy and paste this function in your functions.php file :

function extract_caticonsurl($string,$return_always_array=FALSE) {
	$myarray = array();
	if (preg_match_all('/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i', $string, $matches, PREG_SET_ORDER))  {
		foreach ($matches as $match) {
			$myarray[] = $match[1];
		}
	}
	if ($return_always_array === FALSE && count($myarray) == 1 ) $myarray = array_pop($myarray);
	return $myarray;
}

And paste this code where you want to get the URL(s) :

$caticons_url = extract_caticonsurl(get_cat_icon('echo=false'));

The extract_caticonsurl function returns an array if there’re several icons, or a string (the URL) if there is only one.

How to display category icons side-by-side in a widget

From Daniels (http://www.gameblogs.com.br/) :

I’ve got to make a widget that will show all category icons side-by-side, and not in a list. Here is the code :

$listing_code = '';
foreach(get_categories("orderby=count&order=DESC") as $category) {
$listing_code .=get_cat_icon("echo=false&cat=".$category->cat_ID)." ";
}
$listing_code .= '';
echo $listing_code;

Thanks for sharing, Daniels. 🙂

Update : If you want it in a widget, then you need to create a widget. Copy & paste the following code in a file named myciwidget.php in the default WordPress theme :

<?php

class MyCIWidget extends WP_Widget{
   function MyCIWidget() {
      $widget_ops = array(
         'classname' => 'my_ci_widget', // widget id
         'description' => 'displays category icons' ); // description

      $this->WP_Widget('my_ci_widget', 'My CI Widget', $widget_ops);
   }

	function widget($args, $instance) {
	 	$listing_code = '';
		foreach(get_categories("orderby=count&order=DESC") as $category) {
			$listing_code .=get_cat_icon("echo=false&cat=".$category->cat_ID)." ";
		}
		$listing_code .= '';
		echo $listing_code;
	}

}

Then, in your functions.php file, paste this :

include_once('myciwidget.php');
register_widget('MyCIWidget');

You should be able to add the widget to your sidebar.