image depending on catagory (6 posts)

  1. mrlarter
    Posted 12 years ago #

    I am looking to have the catagory displayed as an image.
    I am currently using the following code
    <img src="/images/<?php echo the_category() ?>.gif" height="100" width="100" />
    but when this displays on the page it shows
    # news
    .gif" height="100" width="100" />
    and news is a link to the catagory. I am suspecting this is because the the_catagory variable. what would should I use?

  2. carthik
    Posted 12 years ago #

    <?php the_category()?>.gif in the place of
    <?php echo the_category()?>.gif
    should fix it.

  3. mrlarter
    Posted 12 years ago #

    nope same problem still
    can bew viewed near the bottom.

  4. carthik
    Posted 12 years ago #

    You can use The template page as a reference.
    <?php the_category_ID() ?> is what you can use to associate categories with posts.
    Hope this helps

  5. davidchait
    Posted 12 years ago #

    Unfortunately, if you use the multi-category features, you need to really be processing stuff by hand.
    I'm on older code, so not 100% sure this matches, but something like this:
    $pcats = get_the_category();
    if (!empty($pcats))
    foreach ($categories as $category)
    // then echo to output what you want to display based on
    You'd want to output something like you started:
    $catidentifier = $acat->cat_name;
    or use ->category_id, or ->category_nicename
    then echo it:
    echo "<img src='images/".$catidentifier.".gif' height='100' width='100' />";

  6. Anonymous
    Posted 12 years ago #

    I can't seem to get that to work, davidchait. whenever i try to load the page with that code in there, i get a blank page. i tried changing "get_the_category()" to "the_category()" as the template page said, but that still doesn't work. also, is there a way to only return the first category that the post is in?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.