Categories Images

Posted by Zahlan on June 4, 2012

Categories Images is a WordPress plugin which allow you to add an image for each category (or term), it is so easy to user. This plugin will create a new text input that will had the image url of the category, in both forms when adding a new category or edit an existing one, you can put a url for the image or upload it bu click on the text input.

Installation:

  1. Open your wordpress admin panel, then plugins menu > Add New and search for ‘Categories Images’.
  2. Click to install.
  3. Once installed, activate and it is functional.

Or you can install in manual:

  1. Download the plugin from WordPress Plugins.
  2. Extract it, then upload the extracted folder ‘categories-images’ to ‘/wp-content/plugins/’.
  3. Go to your wordpress plugins menu, then activate it.

You are done! And the plugin is ready to use.
Usage and documentation:
after installing and activating the plugin, just use the following code:
Default usage:
use the following code in category or taxonomy template,put it in any <img /> tag :

or simply:
Difference between the two methods are as following:
  • z_taxonomy_image_url() return the taxonomy image url as a string so you can put it in any <img /> tag with support of the following parameters:
    • $term_id, the category or taxonomy ID, default NULL
    • $size, default ‘full’
    • $return_placeholder, default FALSE
  • z_taxonomy_image() return category or taxonomy image as html with support of the following parameters:
    • $term_id, the category or taxonomy ID, default NULL
    • $size, image size (check here for more about WordPress image resizing), default ‘full’
    • $attr, array of some html img tag attributes like: (default NULL) please check parameter $attr here
      • alt, default is the image file name
      • class, default is ‘attachment-$size’
      • height, default none
      • width, default none
      • title, default none
    • $echo, to enable or disable printing out the html, default TRUE.
Using inside a loop:
use the following code in anywhere at your wordpress theme, here is an example:
If  looping for categories:

or

If looping for taxonomies:

or

If your post had more than one category and you want to loop for all post categories use the following example:

or

And if your post had more than one taxonomy and you want to loop for all post taxonomies use the following example:

or

Using resizing feature:

To resize category image simply add the size as a second parameter, for example:
if in category or taxonomy template:

or

or if inside a loop:

you can choose to resize from these (thumbnail, medium, large, full) or any custom sizes, also you can use it as array with dimensions for example:

or

Please check WordPress codex here for more information about resizing.

To display image with support for alt, class, width and height, you can do as this example: