How toHow 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.

How toHow to display a list of the categories with icons

Here is an example of how to do that :

echo '<ul>';
foreach(get_categories("orderby=name&order=ASC") as $category) {
    echo '<li>'.$category->cat_name.' '.get_cat_icon("echo=false&cat=".$category->cat_ID).'</li>';
}
echo '</ul>';

Update : As I’ve received e-mails and comments on how to implement it, here is the solution. First, create a new page and put {#caticons_listing} in it. Then, paste the following code in the function.php file of your theme (if the file does not exist, create one) :

add_filter('the_content','bm_caticons_listing');
function bm_caticons_listing($content) {
    $listing_code = '<ul>';
    foreach(get_categories("orderby=name&order=ASC") as $category) {
       $listing_code .= '<li>'.$category->cat_name.' '.get_cat_icon("echo=false&cat=".$category->cat_ID).'</li>';
    }
    $listing_code .= '</ul>';
    return str_replace('{#caticons_listing}',$listing_code, $content);
}

Update 2 : You can use a shortcode : [caticons_listing], instead of {#caticons_listing}, which results in a simpler code, as suggested by Robert of trupela.com (thanks, Rob !) :

add_shortcode('caticons_listing','bm_caticons_listing');
function bm_caticons_listing() {
    $listing_code = '<ul>';
    foreach(get_categories("orderby=name&order=ASC") as $category) {
       $listing_code .= '<li>'.$category->cat_name.' '.get_cat_icon("echo=false&cat=".$category->cat_ID).'</li>';
    }
    $listing_code .= '</ul>';
    return $listing_code;
}

How toHow to display icons in posts

1. download the plugin and install it.
2. Upload your images to your upload folder. The size of the icons depends on your needs & theme. There’s no recommanded size to use the get_cat_icon() function.
3. Assign icons to your categories in Manage tab.
4. Then, in Template Code, the plugin will show you where to put the get_cat_icon() and put_cat_icons() functions in your theme files :

templatecode.jpg
5. You can also use the widget to display icons in your sidebar.

Note that the ‘small’ icons are displayed by default. If the small icons are not found, the normal icons will be displayed, and vice versa. If you have both type (normal and small) and you want to display ‘normal’ icons, you must use set the parameter ‘small’ to false.

Example :

I want to display ‘normal’ icons in my posts. I’ll put that code in index.php (for example) :

get_cat_icon('small=false');

Icon priority by Oliver Weichhold

You can prioritize the display of icons. From the author (Oliver) :”You can now assign numeric priorities to categories. The priority is used to select a single category icon for a post with multiple categories.Example:

imagine we have a post with two categories:

  • Companies -> ACME Corp. (Icon: ACME.gif, Priority 10)
  • Products -> Milk (Icon: Milk.gif, Priority 20)

If you now pass the new boolean parameter “use_priority=true” to the get_cat_icon() function, it will only render Milk.gif, because Products -> Milk has the highest priority of all categories for the post”.

Display icons vertically

You can now display the icons vertically. It’s like a ’stack’ of icons, thank to a new parameter for the function get_cat_icon() : vertical_display. Set it to true if you want to use that feature.

Example :

<?php get_cat_icon(‘vertical_display=true’); ?>

The ’stack’ is generated thank to a div tag. That div tag has a class : caticons. So if you want to extend the style of the div tag, you can use css in style.css.

Example of generated code :

<div class=”caticons” style=”text-align: center; float: left; width:32px“> [the_icons_are_here] </div>

Example of extending the class in style.css :

img.caticons {
border
:0 !important;
}

You can’t modify the value text-align, nor the float value. The width take automatically the larger width of the icons to display.