WordPress.org

Ready to get started?Download WordPress

Plugin Directory

!This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Category Image(s)

Version: 1.7.3 Display an image for each category associated with a post.

Template Tags

The plugin provides one optional template tag for use in your theme templates.

Functions

  • <?php 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 displays the image associated with a post's categories.

Arguments

  • $separator Optional argument. The text and/or HTML to appear between each of a post's category images.

  • $parents Optional argument. Allows you to specify if you want ancestor categories of a post's category to be imaged and linked as well. Valid options are 'multiple', 'single', and ''. Default is ''.

  • $image_extensions Optional argument. A space-separated list of image extensions (case insensitive). 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 argument. The directory in which the category image(s) reside. The value should be a location relative to the main URL of your blog. Default is '/wp-content/images/'

  • $use_name_if_no_image Optional argument. Boolean value (true or false) indicating if the name of the category should be displayed for each category that does not have an associated image. Default is false.

  • $start_from Optional argument. How to traverse the list of post's categories; either 'begin' or 'end'. Default is 'begin'

  • $limit Optional argument. The maximum number of category images to be displayed. Default is 999 (basically, no limit)

  • $post_id Optional argument. The Post ID. If false, then use the current post (i.e. while in the loop). Default is false.

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 based on context where to get the image(s) from:

// In showing the post singularly, then use a larger image, else use a small image
  if ( is_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(', '); ?>
  • Show all images in an unordered list:
<?php c2c_the_category_image();?>
  • Assuming one category per post, just show the category image without further HTML markup:
<?php c2c_the_category_image(' ');  // note the space in the argument, necessary to turn off default <ul> markups ?>

Filters

The plugin exposes two filters and one action for hooking. Typically, customizations utilizing these hooks would be put into your active theme's functions.php file, or used by another plugin.

c2c_get_category_image (filter)

The 'c2c_get_category_image' hook allows you to use an alternative approach to safely invoke c2c_get_category_image() in such a way that if the plugin were deactivated or deleted, then your calls to the function won't cause errors in your site.

Arguments:

  • same as for c2c_get_category_image()

Example:

Instead of:

`<?php $cat_images = c2c_get_category_image( $cat ); ?>`

Do:

`<?php $cat_images = apply_filters( 'c2c_get_category_image', $cat ); ?>`

c2c_get_the_category_image_list (filter)

The 'c2c_get_the_category_image_list' hook allows you to use an alternative approach to safely invoke c2c_get_the_category_image_list() in such a way that if the plugin were deactivated or deleted, then your calls to the function won't cause errors in your site.

Arguments:

  • same as for c2c_get_the_category_image_list()

Example:

Instead of:

`<?php $cat_list = c2c_get_the_category_image_list(); ?>`

Do:

`<?php $cat_list = apply_filters( 'c2c_get_the_category_image_list', '' ); ?>`

c2c_the_category_image (action)

The 'c2c_the_category_image' hook allows you to use an alternative approach to safely invoke c2c_the_category_image() in such a way that if the plugin were deactivated or deleted, then your calls to the function won't cause errors in your site.

Arguments:

  • same as for c2c_the_category_image()

Example:

Instead of:

`<?php c2c_the_category_image(); ?>`

Do:

`<?php do_action( 'c2c_the_category_image' ); ?>`

Requires: 2.2 or higher
Compatible up to: 3.4.2
Last Updated: 2012-6-11
Downloads: 25,949

Ratings

3 stars
3.1 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

0,1,0 100,1,1
0,1,0 100,1,1
75,4,3
100,1,1
0,1,0
0,1,0