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

From Daniels ( :

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 :


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 :


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

17 thoughts on “How to display category icons side-by-side in a widget

  1. There ist another very simple way without making a new widget. You can set the align-Parameter in the Category-Icon-Widget. That will make the icons float: left, menas side-by-side.
    But now you will have the Title of the next widget in the same line. To fix this you can make a simple Text-Widget with the following code in it:


    if you have set align to left. This stops the float at this point. ‘Cause there is no content you won’t see it. Work’s fine on my website and is conform and simple.

  2. This is still not working for me. I’ve created a page called Category Icons, with {#caticons_listing} in the body. I don’t know what the point of this is, because it just creates a page that only says that. That step in the instructions is extremely vague. I put in the code to function.php and modified it to get them side by side. But it’s still not working.

    I also have no idea what LordZed is talking about with setting align-Parameter. Where can you do that? Is it in put_cat_icons() parameters in the widget window? I typed in align-left and it didn’t do anything. I also don’t want the text names, so I had icons_only=true in there, but it got rid of that as well. Is there any way to have multiple parameters?

  3. @Sub
    Thanks Sub, but frankly I still don’t understand.

    May I simply ask — Where should I put the code that Daniels posted above?

    I share the same questions as MaurerPower.


  4. Hi – cool plugin. I’m using this bit of code to display side by side images, but I am not seeing the category name under the image.

    Is there a way to add the category name so it is displayed under each image?

  5. Possible to use the above widget code but sorted by ‘mycategoryorder’ (assuming I have your other plugin installed too)

  6. Category-icon plugin – what i need to do if i want to pull the category description

  7. thank you
    I do not know where to put this code (the first code) would?

    $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;

  8. Hey–this worked beautifully. A couple of questions though:

    1) There’s no option to add a title to the widget. How would I go about doing this? Right now I added an empty text widget above it and it looks like the title for the icons widget.

    2) How would you modify this to get it to work with My Category Order? (If that’s even possible). I tried looking in the original widget to find the code to copy/paste to this one, but while I’m slowly learning PHP, this is still a bit beyond me.

    3)What would the code look like to exclude child categories? (yes, this is a purely wordpress question, but I haven’t quite figured it out via google yet). Right now I’m doing it the long way: exclude=1,3,4,5,6,73,84,85,86,87,88,89,90,91,92,93,94,95 but I would really rather just exclude the category 90 and all its children.

    I know you’ve got a busy life outside the ‘net, but any help (even if its just links pointing me in the right direction) would be appreciated. I’m using the regular version of CI, not the Lite one because why change it if it ain’t broke? ;)

  9. @Tatiana

    So I figured out a workaround for 2 and 3–creating separate widgets for each category, and ordering them by name–but I’m still puzzled about the title thing. My sidebar is getting a bit busy…

  10. Your plugin is great. Thank you for all your hard work.

    Is there a way to display the icons before the post titles in a recent posts sidebar widget?

    Thank you.

  11. @Tatiana

    This code may can help you display all the subcategories icons of the main category:

    Add your main category id here in this area: child_of=23.

    Hope this help. Thanks!