Package/plugin/module WordPress

Plugin: Category Image(s)

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
Category Image(s)
Scott Reilly
Last updated:
17 May 2005
Displays image for each category associated with a post. The number of images displayed can be limited, and the image file extension type and file location can specified.

  • c2c_the_category_image() basically extends the functionality of WordPress’s core function the_category() to add the ability to display a category image instead of the category name in the link to the category archive. The function with its $image_extension argument defaulted to ” could be a drop-in replacement for the_category().
  • As is done the_category(), the image or text for each category is also a link back to that category’s archive.
  • If $image_extensions is defined, but no image is found for the category, then nothing is displayed for that category.
  • The images must be given a nice-name version of the category name. This means all non-alphanumeric characters must be stripped from the name, all letters made lowercase, and all spaces replaced with ‘-‘. For example:
    Category name ==> Nice-name to use for filename :
    WordPress ==> wordpress
    Scott’s Plugins ==> scotts-plugins
  • The number of category links/images displayed can be limited via the $limit argument
  • Category a image <img> tags are defined with class="catimage" for stylesheet manipulation
  • No global site-specific settings need to be configured.
  • Must be run inside “the loop.”
  1. Download the file and unzip it into your wp-content/plugins/ directory.
    Copy and paste the the code ( category-images.phps ) into a file called category-images.php, and put that file into your wp-content/plugins/ directory.
  2. Activate the plugin from your WordPress admin ‘Plugins’ page.
  3. Create category image (.png unless you specify the extension in your call to c2c_the_category_image()) for each category you wish to have an image for, placing the image into the wp-content/images/ directory (unless you specify another location in your call to c2c_the_category_image()). Remember to give the filename the nice-name version of the category name (see note above).
  4. Modify your index.php at a point within “the loop” to make use of the function (assuming, of course, you’ve already defined categories and assigned posts to them). The simplest use would be to replace the index.php call to the_category() with c2c_the_category_image()

function c2c_get_category_image($category, $image_extensions='png gif jpg' $image_dir='/wp-content/images/')

This is a helper function that retrieves the URL of the image for a specified category. Returns ” if no image was found:

  • $category : array for a single category
  • $image_extensions : (optional) a space-separated list of image extensions to consider for use for the image(s) to be displayed, in the order they are to be considered; if defined as ” then no image is retrieved and the category name is displayed instead (a la the_category()); default is ‘png gif jpg’
  • $image_dir : (optional) the directory in which to look for the image(s); default is ‘/wp-content/images/”

function c2c_the_category_image($seperator='', $parents='', $image_extensions='png gif jpg', $image_dir='/wp-content/images/', $use_name_if_no_image=false, $start_from='begin', $limit=999)

This function does the actual display of the post’s category image(s):

  • $separator : (optional) text to insert between each image to be displayed (examples: ‘, ‘; ‘<br />’); if defined as ” (which it is by default), then like the_category(), it will display the image(s) in an unordered list.
  • $parent : (optional) honestly, I’m not quite sure if/when this argument is ever used or what it’s meant for, but I’ve taken it into account; default is ”
  • $image_extensions : (optional) a space-separated list of image extensions to consider for use for the image(s) to be displayed, in the order they are to be considered; if defined as ” then no image is retrieved and the category name is displayed instead (a la the_category()); default is ‘png gif jpg’
  • $image_dir : (optional) the directory in which to look for the image(s); default is ‘/wp-content/images/”
  • $use_name_if_no_image: (optional) if no image for a category is found, should the name be shown instead?; default is ‘false
  • $start_from : (optional) display images starting from the ‘begin’ or the ‘end’; default is ‘begin’
  • $limit : (optional) the maximum number of images to display for a post; default is ‘999’
Tips & Examples:
  • You can opt to treat only certain categories as having a graphical representation by defining an image for them but not creating images for the non-graphically represented categories (as in you can have a subset of categories that dictate what image to be displayed for the post)
  • You can take advantage of the $image_extension and/or $image_dir arguments to display different category icons under different contexts, i.e. if showing a $single post, choose to use a ‘png’ image, otherwise use ‘gif’; or locate your images in different directories ‘/wp-content/images/cat-images/small/’ and ‘/wp-content/images/cat-images/large/’ and decide on context where to get the image(s) from:

    // In showing the post singularly, then use a larger image, else use a small image <?php if ($single) { c2c_the_category_image('', '', 'gif', '/wp-content/images/cat-images/large/'); } else { c2c_the_category_image('', '', 'gif', '/wp-content/images/cat-images/small/'); } ?>

    // Show all images in a comma-separated line <?php c2c_the_category_image(', '); ?>

Related Links:
  • WordPress Support Forums announcement of Category Image(s)
Release Log:
  • 17 May 2005: v1.2 released — Compatibility fix for WP1.5.1
  • 23 Mar 2005: v1.1 released — Same as v1.0 but compatible with WP1.5+
    • Change to accommodate new get_category_link() arguments
  • 23 Mar 2005: v1.0 released — Last version compatible with WP1.2. Changes include:
    • Added argument $use_name_if_no_image=false to allow showing cat name if no image was located
    • Tweaks to update c2c_the_category_image() with changes made to the_category() (mostly rel= stuff)
    • Changed default category images directory from /wp-images/ to /wp-content/images/
  • 12 Oct 2004 : v0.92 released — Fixed a pair of typos that prevented images from showing
  • 23 Sep 2004 : v0.91 released —
    • Now supports listing multiple image extensions
    • Prepended all functions with “c2c_” to avoid potential function name collision with other plugins or future core functions… NOTE: If you are upgrading from an earlier version of the plugin, you’ll need to change your calls from the_category_image() to c2c_category_image()
    • changed from BSD-new license to MIT license
  • 27 Jun 2004 : v0.9 released to the public
Copyright & Disclaimer:

Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


This plugin is essentially an extension of WordPress’s core the_cagetories() function, so the core developers are responsible for a majority of the code present in the function.

149 replies on “Plugin: Category Image(s)”


Great plugin. If I want the category name to display if there is no graphic plug in, where do I make the modification. In the index.php page or in the plug-in.php page. I want the it to be “true”.

$use_name_if_no_image: (optional) if no image for a category is found, should the name be shown instead?; default is ‘false

Here is where I am using it, as an admin-controlled rating system. The stars are your plugin.



thanks for this plugin, I was looking for something like it all over the web! just a small remark: you’re using an ul element to concatenate one or more icons in one list, but it’s not mentioned in the how-to. not being very experienced with wordpress, I was a bit distressed to find the list bullet. I ended up replacing the list elements with just a span. Looks great with the crystal icons by everaldo! has exactly what i need. Images auto assigned to a certain category on the left of the textual content in each and every post.

I need a script that puts this code next to the content text (on the frontpage)
where img src is automatically assigned to the category iam posting into.

Could anyone help me out into getting this?

Hi. I am new. I have installed and activated the plugin.

However my index.php does NOT contain any the_category() entries. How do I proceed?
Sorry for the silly question.

[…] Il plugin di cui vi parlo oggi è Category Image(s) di Scott Reilly. Potete scaricarlo da qui. La funzione del plugin in questione è quella di associare una immagine a ciascuna categria del vostro blog. L’installazione è la solita : copiare il file category-images.php nella votra directory dei plugin. E’ poi necessario attivare il plugin. Bisogna poi creare le immagini di categoria. Io ho usato dei piccoli file png. Le immagini vanno messe nella vostra directory wp-content/images/ altrimenti bisognera editare il file del plugin. La cosa importante perchè queste possano essere visualizzate e assegnare ai file delle immagini il cosidetto “nice-name”. Cioè il nome della categoria tutto minuscolo, se questo contiene spazi dovete rimpiazzarli con simbolo_. Per esempio il file di immagine della categoria “Non Categorizzato” si dovrà chiamare “non_categorizzato.png (per esssere chiari). Ultimo passo da compiere è quello di aggiungere il tag “< ?php c2c_the_category_image(‘ ‘); ?>” per visualizzare le immagini corrispondenti alle categorie. Io ho inserito il tag nel mio file post.php e l’effetto è quello che vedete in alto. Spero di esservi stato utile.   […]

I use the plugin, and it works fine, but it doesnt work, if a category has no posts itself, but some filled subcategories. How do I have to call the c2c_the_category_image function to get an image for “emtpy” categories anyway?

Er, not quite sure WHERE to put the code. My index.php in my root folder is just:

I also checked the template index.php:

Posted in | |‘); ?>

Was about as close as it got. I know I’m missing something stupid and obvious…help me out here ;x

Scratch that, I’ve worked out you stick it in the theme index.php, however no image shows: I have used the nicename for the category (general) and I’ve put it in the right folder (wp-content/images) and placed in the code

But no image appears.

I followed all the instructions exactly. The images will still not post, although if i change the value from false to true to show the names if the images are not found, then that works. Very strange. I’ve tried gifs and pngs. Both should work, but don’t.


Yet more work behind the scenes, I’m adding some WordPress Plugins so expect some strange site behaviour. Like zebras and spacehoppers, nothing working and screens of code. Sorry but I apply changes to the live site to see what happens, it’…

I am trying a little different approach on my site Using the plugin at the bottom of each post right next to the category name. It’s working but I have 2 small problems –
1. Can anyone tell me where the . on the left of the images is coming from?
2. Also why are the images on a separate line from the rest of the links at the bottom of the post.
Thanks – any help is appreaciated.
I can post code from any pages needed if that helps.


I’m not getting the links to come through with the images since WP 2.0. Each image has the link “” when there should be the category name after the last “/”. Has anyone else seen this?

Hello, great plugin but i’ve got a problem. I used the new version of wordpress 2.0.1 and activate your plugin, nice-named the images and then want to put the code in my index.php but there’s a problem.

i used the blix-theme but there is no the_category () in it.

How can i install it then.

Greetings eric

I’ve installed the plugin- I’m using wordpress 2 – but I cannot get this to work for me.

I have a category called stories and an image called stories.gif. I am calling the function . I have defined the path in the php file itself.

What am I doing wrong? Any guesses???

thanks so much for your help.

Is there any way to use this in the sidebar? I would like to have it show in posts (next to the category name) and in the sidebar next to the category name. I’m not such a great programmer, but I can usually hack things together through trial and error. Unfortunately, nothing’s worked for me so far. I can’t hard code the icons in the sidebar because the categories are called with PHP.


You should really make it more obvious that the edit needs to be done to the template not the actual index.php in the root. Took me a few minutes, err more like 30, to figure it out. I’m a dummy.

Other then that I LOVE IT! Thank you ^_^

Just started WPress. Hey, is there a link to an “idiots” guide to using your plug-in? In your installation instructions it ends at copying the php into my root directory. I’m using a custom theme. I just want to hack this in. On which existing php (like style.php etc) do you I use to “call” the function. As you can tell I’m really green and basically have no clue. Any resources would be great. Thanks!

[…] One of the reasons for not posting to my (old) blog for so long was that iBlog became so unreliable that I was afraid another post would further corrupt its database. I finally decided that the only way to save this blog from oblivion was to reactivate it and put it at a place that I trust (Dreamhost) using commonly used software (WordPress). I thought about using iWeb but couldn’t find anything that would help me converting iBlog entries to iWeb. Instead my search uncovered Agitprop which converted my iBlog entries to the Movable Type import file format which I then imported into my freshly installed WordPress (Dreamhost’s 1-click installation rocks!). Agitprop refused to convert my image links into proper URLs (the URL field in Option had no effect and the URLs where missing one of the initial “//”) but a quick use of vi fixed that problem. The formatting is still not where I want it to be but this will have to wait. With coffee2code’s plugin I even got to incorporate category images. […]

[…] Je suis entrain d’installer quelques pluggins, pour parfaire le site, avant le launch officiel. Je viens de terminer l’installation du pluggin Category Image, il permet d’avoir une image de la catégorie sur le coin gauche (pour ma part) du post. En attendant, la mise en page, parceque la couleur verte, là, c’est un peu…Je trouve pas la description… […]

It does not appear to work with WP 2.1.

I used this with WordPress 1.5, and 2.0. When I upgraded to 2.1, if I enabled the plugin all I got was blank pages, or pages of junk.

I don’t know what’s going on, or how to debug it right now. I’d be happy to help if I knew how.

I did get this to work. Something causes the gzip compression to send unreadable pages with category-images enabled.

Log in as an administrator, go to Options then Reading and uncheck “WordPress should compress (gzip) articles if browsers ask for them.”

That fixed Category Images 1.2 under WordPress 2.1 for me.

Comments are closed.