- Two new tabs added : How To (WP 2.8 only) & Support the plugin
Since v2.1, you can display the category icons with Rob Marsh‘s Recent Posts plugin. Here is how. In Recent Posts, go to Output, enter {caticons} in the field, and click on Save Output Settings :
If you use the widget, it’ll be displayed like this in the default WordPress theme :
Continue reading
Thanks to Shlizer (http://shlizer.ayz.pl) for his work ! Download the plugin (v2.1) again to get the polish language.
In a previous post (“beware of imitations“), I said that Category Icons Premium Module for Another WordPress Classifieds Plugin was an imitation and that you should not buy a plugin that you could have for free. Well, I was mistaken : the author sent me the source code, and it’s not comparable to the WordPress Category Icons plugin. So, I made a mistake, and I apologize to A. Lewis for my error. I’m sorry.
A new language is added to the plugin translations : belarusian (belorussian). This translation is for the version number 2.0.7 of the plugin but it’ll work with the last version, of course. Thanks to Fat Cower (http://www.fatcow.com) for his work. Download the plugin (v2.1) again to get this update.
Thanks to Gianni (www.gidibao.net) : the italian language is updated to the last version of the plugin. Download the plugin again to have this update.
Someone is using the put_cat_icons tag in order to display his categories and subcategories in archive.php. This presents a sizeable icon for each subcategory of the currently selected category. How to do this :
$cat = get_cat_ID( single_cat_title("", false) );
put_cat_icons( wp_list_categories('hide_empty=1&orderby=name&echo=0&depth=1&title_li=&child_of='.get_cat_ID( single_cat_title("", false) )));
The problem is that when there is no subcategory, “No categories” is displayed. So to hide this, we’ll use another filter this time, named wp_list_categories. Paste the following code in your functions.php file in your theme.
function bm_dont_display_it($content) {
if (!empty($content)) {
$content = str_ireplace('<li>' .__( "No categories" ). '</li>', "", $content);
}
return $content;
}
add_filter('wp_list_categories','bm_dont_display_it');
If you want to center text vertically after the icons, just as I do, you need to add this in your CSS stylesheet (style.css) :
.myicons {
vertical-align: middle;
}
Add this in your theme files :
get_cat_icon('class=myicons');
If you want to add this in sidebar.php without using the widget, you should have something like this :
if (function_exists('put_cat_icons'))
put_cat_icons( wp_list_categories('title_li=&echo=0'),'class=myicons'));
else
wp_list_categories('title_li=');
For the widget, put this in the parameters field :
class=myicons
Category Icons Widget
Please, please, use Firebug to test your CSS settings.
Suppose you have categories that don’t have yet an icon assigned to. If you want to display a default icon instead of nothing (no icon), here is the code that you must paste in functions.php (in your theme) :
function bm_noicon($content) {
if (empty($content)) {
$content = '<img src="http://yourdomain.com/wp-content/uploads/cisco.gif" alt="default icon" />';
}
return $content;
}
add_filter('category_icons', 'bm_noicon');
Of course, you need to replace http://yourdomain.com/wp-content/uploads/cisco.gif by your own icon/image URL.
Someone (onkelandy from Weeds ?
) asked me if it was possible to assign a specific icon for just a post :
Normally icons are shown depending on the category a post is put in. If a post is related to several categories the priority system comes into place. Anyhow there are some cases where that icon just doesn’t fit to a specific post. So it would be very cool if it was possible to define a specific icon/icon category for just that post by using the “custom field” that appears on the “create post” page in the admin area.
Yes, it is possible, thank to the filter ‘category_icons‘, as I’ve written about in this post. Just make sure you add a custom field named “caticons” and the URL of the icon/image as the value. Paste the following code into functions.php of your theme :
function bm_unic_icon ($content) {
$values = get_post_custom_values("caticons"); // Get the values of the field 'caticons'
if (isset($values[0])) {
$content = '<img src="'.$values[0].'" alt="my specific icon" />'; // Get the icon URL
}
return $content;
}
add_filter('category_icons', 'bm_unic_icon',15); // Use the filter 'category_icons'
Of course, it’s up to you to customize the 4th line, in order to make a W3C compliant output, for example…
Update : I apologize to A. Lewis for my error.
I’ve found that this website : http://www.awpcp.com/premium-modules/category-icons-module/ is selling a WordPress plugin called Category Icons for $10.99 !!! Here is how they describe it :
Category Icons Module
Category Icons Premium Module for Another WordPress Classifieds Plugin – $10.99
This module allows you to add icons to your categories and subcategories. The silk icon pack from famfamfam.com is included in the default package. You can always use your own icons by uploading them to the images/caticons folder. Adding your icons is a simple matter of selecting the icon you want to use for a specific category and clicking a button to set it. (If you have previously made a donation of $10 or more please contact me for a free copy of this module)
It sounds familiar, does not it ? Even the famfamfam icon pack I’ve talked about here. So don’t buy a plugin that you could have for free by downloading it !
Almost one year without update, but here it is :
The translations need to be updated. You’ll find all the .po files in the archive if you’re willing to help. Thanks for that.
Make sure the .pot file creation date is :
POT-Creation-Date: 2009-07-23 12:43+0100
Or download it from the svn repository.
If you want to test the beta version, here it is, but remember : for testing purpose only !
For those having the following error :
Syntax error, unrecognized expression: [@name='igcaticons_spacerstype'][@value='image']
category_icons-links-panels.js:2TypeError: Result of expression ‘jQuery(”div#slider1″).codaSlider’ [undefined] is not a function.
just comment this line (it should be line number 547) :
wp_enqueue_script('caticons-links-panel', '/wp-content/plugins/category-icons/js/category_icons-links-panels.js');
Update 2 : the patch is not needed anymore as there is a new version of category icons (2.1) that is compatible with WordPress 2.8+. Download it to resolve the issue.
Update 1 : here is the detailed procedure (thanks to ycs for the tip) :
Please leave me a comment if it’s not working.
If you have a category.php page & want to display the category icon in it, here is the code :
get_cat_icon("cat=".get_cat_ID( single_cat_title("", false) ));
Someone asked me how, so here it is. Paste the following code in style.css of your theme :
ul, li {
display: inline;
}
For example, for the default WordPress theme, it will be :
#sidebar ul, #sidebar ul li {
display: inline;
}
It’s up to you to find the correct CSS code, as the themes have different stylecheets. My only advice would be to play with FireBug, a FireFox plugin.
As you can see, I’ve finally found icons for my categories…
Long time without updates : lot of work and family stuff… But let’s come back to the list. Here is an example of how to do that :
echo '<ul>';
foreach(get_categories("orderby=name&order=ASC") as $category) {
echo '<li>'.$category->cat_name.' '.get_cat_icon("echo=false&cat=".$category->cat_ID).'</li>';
}
echo '</ul>';
Update : As I’ve received e-mails and comments on how to implement it, here is the solution. First, create a new page and put {#caticons_listing} in it. Then, paste the following code in the function.php file of your theme (if the file does not exist, create one) :
add_filter('the_content','bm_caticons_listing');
function bm_caticons_listing($content) {
$listing_code = '<ul>';
foreach(get_categories("orderby=name&order=ASC") as $category) {
$listing_code .= '<li>'.$category->cat_name.' '.get_cat_icon("echo=false&cat=".$category->cat_ID).'</li>';
}
$listing_code .= '</ul>';
return str_replace('{#caticons_listing}',$listing_code, $content);
}
Update 2 : You can use a shortcode : [caticons_listing], instead of {#caticons_listing}, which results in a simpler code, as suggested by Robert of trupela.com (thanks, Rob !) :
add_shortcode('caticons_listing','bm_caticons_listing');
function bm_caticons_listing() {
$listing_code = '<ul>';
foreach(get_categories("orderby=name&order=ASC") as $category) {
$listing_code .= '<li>'.$category->cat_name.' '.get_cat_icon("echo=false&cat=".$category->cat_ID).'</li>';
}
$listing_code .= '</ul>';
return $listing_code;
}
See a demo here : http://www.trupela.com/2009/11/16/a-post-is-a-category-is-a-story/
As you can see, I don’t have icons for my categories. I’ve been searching around for icons, but unfortunatly, I couldn’t find ones corresponding to my categories.
So I’m searching for a volunteer who would create icons for my categories :
Documentation, How to, FAQ, Translations, Changelog, News, Tips & Tricks
If someone wants to help, you’re welcome !