• 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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php the_category()?>.gif in the place of
    <?php echo the_category()?>.gif
    should fix it.
    ??

    Thread Starter mrlarter

    (@mrlarter)

    nope same problem still
    https://www.memenetphoto.com/
    can bew viewed near the bottom.

    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

    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′ />”;
    -d
    https://www.chait.net

    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘image depending on catagory’ is closed to new replies.