How toHow to use Category Icons tags in a script

Sometimes, you need to use the tag get_cat_icon or/and put_cat_icons in a script. So to get the icon in a variable, it must not be displayed. The parameter to not display the category and to get it returned is : echo, and it needs to be set to false. Here are examples of how to use it. If your script is not in the Loop, you must use the cat parameter and give it a category id. Continue reading

How toHow to find where to place the get_cat_icon tag ?

First, remember that the Category Icons plugin just generates images tag, nothing more. Thus, you can first work with an image in your theme, and when you are satisfied, replace that image with the get_cat_icon tag.
Through the Template Tags panel, your template files are scanned and patched if they’re writable. If not, informations about where you should paste get_cat_icon() in your files are displayed : line number and the column number. These locations are just where you COULD paste the tag, not where you MUST paste it. It’s up to you to find the appropriate location within your template files. The tag is usually within the Loop. A blue arrow shows you where to paste the followin code :
<?php if (function_exists('get_cat_icon')) get_cat_icon(); ?>

Nota Bene : If you don’t want your files to be patched automatically, make sure it’s not possible to write into them by checking the permissions.

Template Tags

Template Tags

If you want to place it in another place than in the Loop, you should read this post.

DocumentationFunction : get_cat_icon()

The size of the icons depends on your needs & theme. There’s no recommanded size to use the get_cat_icon() function.

The function get_cat_icon() return boolean True if an image is found. You can use the following parameters.

type parameter summary
boolean align align attribute for the image tag
boolean border If true, displays the icon with a border. If false, no border is diplayed. (Don’t use this if you want valid Strict XHTML)
int cat Category ID. If not specified, the current category is used or the current post’s category.
string class Class attribute for the image tag.
boolean echo If true the html code will be ‘echoed’. If no, it’ll be returned. Default : true
boolean expand Whether the image should be expanded to fit the rectangle specified by fit_xxx. Default : false
int fit_height Maximum height (or desired height if expand=true) of the image. Default : -1
int fit_width Maximum width of the image, or desired width if expand is true. Default : -1
boolean hierarchical If true, displays the icon in hierarchical order. Default : false
boolean link If true, an anchor tag wraps the image (a link to the category is made). Default : true
int max_icons Maximum number of icons to display. Default : 3
string prefix String to echo before the image tag. If no image, no output.
boolean small Use the small icon. Default : true.
string suffix String to echo after the image tag. Ignored if no image found.
boolean use_priority If true, only the most prioritized icon will be displayed. Default : false


This example will insert the icon associated with the current category:

<?php get_cat_icon(); ?>

Here is an example of how to use it in index.php of your theme directory :

<div class="left_side">
if (have_posts()) :
  while (have_posts()) : the_post();
    if (function_exists('get_cat_icon'))

Example of class attribute for the image :

.myicons {
margin : 0 3px 0px 0;

This example inserts icon for the category with ID ‘5′. The image is fitted withing rectangle 100×100. If the image is smaller than desired, it is expanded :

<?php get_cat_icon('cat=5&fit_width=100&height=100&expand=true'); ?>

More examples.

If you’re wondering : where to put the get_cat_icon() code, read this.