• Anyone know how I can add icons to the left of each category listed in the sidebar? What code would I need to add in the “template-functions-category.php” file? I’ve seen plugins to add a category image to posts, but not to the sidebar.

Viewing 6 replies - 1 through 6 (of 6 total)
  • A quick glance on the code…
    1. Find the following line in function get_the_category_list()
    $thelist .= “\n\t<li>“;

    2. Replace the above line with the following
    $thelist .= ‘\n\t<li id=”$category->cat_name”>’;

    3. Backup (Oopps. Too late!)

    Of course, the above code won’t display any icons. You still need to call the icons via CSS.

    Thread Starter fuddes

    (@fuddes)

    Thanks, alphaoide. You were very close. Here’s what I did. I named all my category icons the same name as the categories they represent. Then I added an image tag, using the category variable instead of an image name. The original code (around line 361) is:
    $thelist .= "t<li>$linkn";

    Change it to the following, substituting the location of your category images and the image type (.gif, .jpg, etc):
    $thelist .= "t<li><img src="https://YOURDOMAIN.com/$category->cat_name.gif"> $linkn";

    Thread Starter fuddes

    (@fuddes)

    Okay, this ridiculous support forum won’t post the code correctly, even with the code tags and the backticks. In the code above, the “n” after each $link and the “t” before each <li> should have a backwards slash in front of them.

    This is the closest I’ve seen to what I want to do. I already have the Category Icons plugin working properly in my post titles… now I want to add the icons to the left of each category name in the sidebar. I will be adding categoris alogn the way and would prefer if they’re dynamic and not hand-coded each time I create a new one.

    However, I don’t see where the above code would go. In my sidebar php file categories are called with the following code:

    <li>
    <h2><?php _e('Categories'); ?></h2>
    <ul>
    <?php list_cats(0, '', 'name', 'asc', '', 1, 0, 1, 1, 1, 1, 0,'','','','','') ?>
    </ul>
    </li>

    Here’s my blog if you need a reference point: Me-Go

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Category icons in sidebar’ is closed to new replies.