Forums

First Post - Be Kind (3 posts)

  1. Cursh
    Member
    Posted 2 years ago #

    firstly - I don't think I'm familiar enough with the terminology to successfully search the forums (I will get better at this with time)

    What I am interested in doing is setting up icons in front of post titles that is based on the category has been placed in.

    I want a click on this icon to screen the content to exclusively display that tag.

    Example.
    <img src="http://hipstersighting.com/Example.jpg">

    In this example I would want to click the bike to get to all posts about bikes.

    The only thing I can think of is to make new author for each of the categories and set the icon as their avatar, which works for me since Its a single author blog, but I'm sure there is a better way.

    Any Help is much appreciated.

  2. alchymyth
    The Sweeper
    Posted 2 years ago #

  3. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You can use the post_class() function to apply specific classes (including those based on category name/slug) to each post.

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2 class="post-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    [ ... ]

    This will give you a whole stack of classes to play with such as post-150 post sticky hentry category-music tag-piano. You then use these in your CSS to apply icons to the post titles.

    .post-title {padding-left:20px;}
    .category-music .post-title {background:url(images/music.gif) no-repeat left center;}
    .category-bikes .post-title {background:url(images/bike.gif) no-repeat left center;}

Topic Closed

This topic has been closed to new replies.

About this Topic