WordPress.org

Ready to get started?Download WordPress

Forums

Changing icon based on post type (3 posts)

  1. DrBrianFields
    Member
    Posted 6 years ago #

    Hey all, I was wondering if there was a way to change an icon next to my subject line based on the type of post I'm making. eg, a post about a trip I took will have an icon of the world, a post about pictures will have an icon with a photograph, etc.

    If you need an example here is my site: http://www.renegadeonline.net/

    Please note that currently only the "bio" and "contact" links work... I've set them up to give an idea of how I want it to work, but I was wondering if there was a way to do it without having to add code when I'm making a post... perhaps a drop down menu of the pre-made icons I want or something.

    I just upgraded my version today and noticed an area where I can add a custom field... perhaps this would be the easiest way?

    Any help or suggestions would be appreciated.

  2. Eric Amundson
    Volunteer Moderator
    Posted 6 years ago #

    Yes. There are probably a few ways to do this. I haven't done it yet, but will be implementing something similar on another site soon.

    Dan Cederholm does a similar thing on SimpleBits.com.

    You may check out:
    http://codex.wordpress.org/Template_Tags/get_the_category

    I'd start by adding a class to the <div class="post_header"> based on the category or category ID.

    So for a category named 'travels' you'd setup the template with a snippet of code that output the category name(s) or ID.

    So the output might look like:

    <div class="post_header travels">My trip to Spain</div>

    Then, in your CSS, you'd set a different background image for each class of category-specific div.

    This would probably work best if you only assign one cat per post.

    If you have multiple categories per post, you could try to use the Custom Fields and implement a little PHP that looks for the presence of a custom field named, say 'icon' and if it's there, reads the value of that field and outputs it in your markup.

  3. submarine
    Member
    Posted 5 years ago #

    Hi,

    here is a plugin for that :
    http://www.category-icons.com

Topic Closed

This topic has been closed to new replies.

About this Topic