Ready to get started?Download WordPress


How to add Category Icons? (12 posts)

  1. TechGnome
    Posted 11 years ago #

    are you using the friendly urls? (ones that look like this: http://www.mysite.com.posts/2004/1/1/title_of_post_here)
    I found that this can "break" image links unless the image has the full path.
    If your images are in an image folder in the root, you might find this works...
    <img src="/images/<?php the_category() ?>.gif" alt="<?php the_category() ?>">

  2. Jason
    Posted 11 years ago #

    The problem is that the_category() returns an unordered list of categories, not just the name. While that can be easily changed with a parameter, there's also the fact that multiple categories for any given post would mess things up.

  3. tarheelian
    Posted 11 years ago #

    TechGnome, I tried moving the images into a separate folder but it still does not work. Jason, what parameter needs to be changed to make category images work? Thanks!

  4. timsamoff
    Posted 11 years ago #

    Might be so simple that it's stupid, but I just entered a <img src> tag in place of an actual "name" for the category. Seems to work pretty good.

  5. WillM
    Posted 11 years ago #

    Have you tried numbering the icons and using the_category_ID?
    On second thoughts, I'm not 100% sure the_category_ID still exists - haven't tested it lately - so try inserting a comma in the parameters for the_category.

  6. tarheelian
    Posted 11 years ago #

    WillM, what do you mean by adding a comma? I mean, how would I write that out? I am not very seasoned in PHP, sorry! Thanks everyone for all your help!

  7. WillM
    Posted 11 years ago #

    My suspiscion was correct: support for multiple categories seems to have eliminated the_category_ID:
    I tried to see whether it was still in the Wiki but I couldn't access the page.

  8. tarheelian
    Posted 11 years ago #

    Oh, ok. Thanks for all your help again!! :)

  9. Matt Mullenweg
    Posted 11 years ago #

    I wrote a function that allows you to do this with multiple categories, it's available here:

  10. Jean-Pierre Michaud
    Posted 11 years ago #

    sugg: why not use the upload function to add some images in the directory we choose, and once it's done, in the category creation page we can select inside the list of image the one chosen for that category... a simple drop-down listing the content of the upload directory can do the trick... once it's selected, it's entered in the category table (we have to add a field then) ... this would make the image available only if there is one entry in the category table...

  11. pIng
    Posted 10 years ago #

    Instead of using complex hack code, I chose to simply search the query string for the category number, then I've inserted it inline where needed to modify image or css tags. I'm no PHP guy, but this works great for me and it's one line of code:
    <?php echo($cat); ?>

  12. Anonymous
    Posted 10 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.