Support » Fixing WordPress » Cat Images using the_title

  • Simple question really – I know WP has the built in function use category images per cat, so rather than going the plugin route I’m trying to use as many built-in functions to achieve the output i need without plugins.

    I’m trying to use cat images, and can’t find within the codex what I’d need to use in order to call a category image.

    The code is currently as follows:

    <a class="title" href="<?php the_permalink() ?>" style="text-decoration:none;" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title('-image-'); ?></a>

    It’s the (-image-) bit that I need to fill. I thought something like $catID might work as I want to display the image based on the cat, but I’m not sure.

    Thanks in advance

    EDIT: I found this bit:

    But it doesn’t explain in the example what I’d add to call the image

Viewing 12 replies - 1 through 12 (of 12 total)
  • thanks firas, could this example be added /updated to the codex – seems a strange omission for confused fools like myself.


    EDIT: Doesn’t seem to be working, obviously it’s me, but anyway the code is:

    <?php foreach((get_the_category()) as $cat) { ?><img src="<?php echo $cat->cat_ID; ?>.gif" />

    the output is:

    <img src="" />

    It’s not picking the image up based on id.

    Actually to be fair I can’t remember:

    1) where the images need to go
    2) what form the images must take (ie, catname nicetitle, catid num

    So I need to clear that too.


    Hm.. that really can’t not work 🙂 Paste your loop at pastebin?

    To see what’s in the get_the_category array just in your loop do this:

    <?php var_dump(get_the_category()) ?>

    here’s the pastebin:


    I replaced a loop with that–from line 1 to 35–and it worked for me: <img src="" />. What version of WP do you run?

    1.5 – with the fix – i’m not really wanting to update to another version to be honest, it just seems too much for little me 🙂

    i note you used the number rather than cat name – that’s probably where i messed up.

    cheers again firas – codex def needs some clarity in this area, but I guess sense works too 🙂


    Heh. I’ll get to it in an hour or two (Really!), at which point you can use name, nicename, id, etc.

    just to clarify though, do i have to specify the image, or should the image call on its own, without the need for a specific name?

    oh and i wasn’t rushing you on the codex thingy, i was just writing out loud 🙂

    EDIT: bugger still not working for me the output is still:

    <img src="" />

    Do the var_dump thing inside the loop. What does it output?

    do i place it anywhere in the loop?

    array(1) { [0]=> object(stdClass)(6) { ["ID"]=> string(3) "153" ["category_id"]=> string(1) "1" ["cat_name"]=> string(22) "daily regular chickens" ["category_nicename"]=> string(22) "daily-regular-chickens" ["category_description"]=> string(109) "the class c, none harmful items which are unlikely offend anyone but those of a sensitive, egotistical nature" ["category_parent"]=> string(1) "0" } }

    You’ll have to do $cat->category_id then (or $cat->category_nicename, or whatever else strikes your fancy from that list)… now I’m really confused about whether it’s cat_id or category_id in up-to-date versions.

    that was my thought too, it’s not a feature that is really promoted, nor one that has been covered in any great detail which is a shame as it negates the need for a plugin. i#ll give it a go and report back

    ok that worked 😉


Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Cat Images using the_title’ is closed to new replies.