Grow your CSS skills. Land your dream job.

Post Thumbnail Based on Category

  • # April 15, 2010 at 12:26 pm

    I’m making a ton of icons to be used in the custom field area. Balloons for birthdays/anniversaries. trophy for awards, etc etc. The icons correspond with the category the post belongs in. is there a way to automatically spit them out in the loop next to the post title based on the posts category?

    anybody done this before?

    # April 15, 2010 at 1:20 pm

    I have no idea if this is possible. This is just a theory, and the code is probably wrong:

    <?php echo get_post_meta($post->ID, the_category(), true); ?>

    So, you would name all of the custom fields by the category that they relate to.

    # April 15, 2010 at 2:27 pm

    i should have added that i want to spit them out without having to enter anything in the custom field but using the custom fields was my first approach. this is for an internal blog used at my work. Any employee can use it so i was hoping to have it all automated. they just need to pick the category and if there’s a corresponding image it shows up. if not the title is just left aligned.

    think what you’re saying would work in this condition?

    trying to avoid teaching anybody how to use custom fields if i can.
    having it show up if ones available would be idea. i found this but i havent looked over it completely yet.

    http://markjaquith.wordpress.com/2009/1 … il-images/

    not sure if thats exactly what im looking for or not.

    # April 15, 2010 at 2:42 pm

    Ah, right, that makes more sense, let’s ignore custom fields altogether!

    This could be tedious depending on how many categories you have, but you could simply hard code it into the template and run some wonderful queries on the loop based on the category.

    # April 15, 2010 at 2:52 pm

    like a lot of if else logic stuff?

    i have no problem with going the hard coding route if needed. think thats the best option?

    # April 15, 2010 at 3:16 pm

    It makes the most sense to me, to be honest.

    Plus, pretty quick to add another category in there should you need to expand it.

    # April 15, 2010 at 3:49 pm

    true. alright i’ll give that a go. thanks!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".