Forums

[resolved] category image (4 posts)

  1. Sinopa
    Member
    Posted 3 months ago #

    I wonder if there is someone here that can help me with a "small" problem :)

    I use <?php the_category(',') ?> in my posts, but I would like to use custom images instead of a text link that <?php the_category(',') ?> generates.
    If I have a category that's called wordpress, I would like it to display a small wordpress logo for category with a link to that category.

    Is this possible? :)

  2. ysr5
    Member
    Posted 3 months ago #

    what about this:

    <?php
    if ( is_category( 'wordpress' ) ) {
    $imagePath = 'pathToWorpressImage.png';
    }
    ?>
    <img src="<?php echo §imagePath;?>" ...>

    you could create a category array with wp_list_categories(); and identify with is_category(); in which category you are and generate a $imagePath you want to display belonging to the different categories.

  3. Sinopa
    Member
    Posted 3 months ago #

    I did like this instead :)

    <?php foreach((get_the_category()) as $cat)
    	{
    	$catname =$cat->category_nicename;
    	echo "<img src=\"/wp-content/cat-icons/$catname.png\" title=\"$catname\" border='0' />\n";
    	}
    ?>
  4. ysr5
    Member
    Posted 3 months ago #

    much butter dude :-)

Reply

You must log in to post.

About this Topic