• Resolved altexasgirl

    (@altexasgirl)


    Hi – I’m using the latest (2.3.3) version of WordPress and am trying to display a category image.

    I copied the code from the Codex into my theme’s archive page template and all went well – as long only one category is used per post. Apparently it tries to display images for all the categories listed.

    As I want this on a category page, I want it to recognize that category, not the post’s category. I’m not sure if this makes sense, but I hope someone can help me out! Thanks!

    I don’t know much about PHP, but I have a feeling that the foreach is what’s messing me up.

    <?php
    foreach((get_the_category()) as $category) {
        echo '<img src="https://example.com/images' . $category->category_nicename . '.jpg" class="alignleft" alt="' . $category->cat_name . '" />';
    }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Only One Category Image’ is closed to new replies.