WordPress.org

Ready to get started?Download WordPress

Forums

How to add Category Icons? (12 posts)

  1. TechGnome
    Moderator
    Posted 10 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...
    <pre>
    <img src="/images/<?php the_category() ?>.gif" alt="<?php the_category() ?>">
    </pre>
    TG

  2. Jason
    Member
    Posted 10 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
    Member
    Posted 10 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
    Member
    Posted 10 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.
    Tim
    http://www.sense-datum.org/tim

  5. WillM
    Member
    Posted 10 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
    Member
    Posted 10 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
    Member
    Posted 10 years ago #

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

  8. tarheelian
    Member
    Posted 10 years ago #

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

  9. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

    I wrote a function that allows you to do this with multiple categories, it's available here:
    http://wiki.wordpress.org/index.php/CategoryImages

  10. Jean-Pierre Michaud
    Member
    Posted 10 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
    Member
    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
    Unregistered
    Posted 10 years ago #

    Hi

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.