How to display icons for pages in the sidebar

I’ve written a function that seems to be working. I think I’m going to include it in a future version of my Category Icons plugin. So, you can have page icons the same way you have category icons in the sidebar.

The following code will add icons in front of the title page in the sidebar when you use the Pages widget. You can see that I’ve used a filter named widget_pages_args to add the filter wp_list_pages in order to parse the HTML generated by wp_list_pages. It’s because I want to display icons only in the sidebar and nowhere else.

To use that code : Continue reading

How to display category icons in the sidebar

To display the icons in the sidebar, you have 2 solutions :

1. Use the widget
Go to Appearance > Widgets and drag Category Icons Widget to the right. You can have multiple Category Icons widgets.

Category Icons Widget

Category Icons Widget

Category Icons Widget Settings

Category Icons Widget Settings

Here is a good & complete spanish tutorial.

2. Manually

In the sidebar.php page of your WordPress theme, you must use the put_cat_icons function.

UA:F [1.6.2_892]

How to assign an icon to a page

In a previous post, I described how to do this with the help of another plugin : Page Category Plus, but this plugin does not exist anymore, so here is another way to do that.

I’ll use the theme “lightword” for this how to. There is 2 parts :

1. Assign a category to a page

When you’re editing the page, go to the Custom Fields, and add : caticons_page as the key, and in the value field, enter the ID of the category to which the icon is assigned to. It’s like assigning a category to a page.

The icon is assigned to the category ID 4

The icon is assigned to the category ID 4

Use the Custom Fields to display a "Page Icon"

Use the Custom Fields to display a "Page Icon"

2. Use the get_cat_icon tag to display the icon

In the page.php file, after this line : Continue reading

How 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 to hide No categories if there are no subcategories

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;