WordPress.org

Ready to get started?Download WordPress

Forums

Cat Images using the_title (13 posts)

  1. Jinsan
    Member
    Posted 8 years ago #

    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:

    http://codex.wordpress.org/Template_Tags/the_category_ID

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

  2. Firas
    Member
    Posted 8 years ago #

  3. Jinsan
    Member
    Posted 8 years ago #

    thanks firas, could this example be added /updated to the codex - seems a strange omission for confused fools like myself.

    cheers

    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="http://sekhu.net/wp/wp-content/my-images/<?php echo $cat->cat_ID; ?>.gif" />

    the output is:

    <img src="http://sekhu.net/wp/wp-content/my-images/.gif" />

    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.

    Cheers

  4. Firas
    Member
    Posted 8 years ago #

    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()) ?>

  5. Jinsan
    Member
    Posted 8 years ago #

    here's the pastebin:

    http://paste.uni.cc/7157

    Cheers

  6. Firas
    Member
    Posted 8 years ago #

    I replaced a loop with that--from line 1 to 35--and it worked for me: <img src="http://sekhu.net/wp/wp-content/images/1.gif" />. What version of WP do you run?

  7. Jinsan
    Member
    Posted 8 years ago #

    1.5 - with the 1.5.1.1 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 :)

    thanks

  8. Firas
    Member
    Posted 8 years ago #

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

  9. Jinsan
    Member
    Posted 8 years ago #

    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="http://sekhu.net/wp/wp-content/images/.gif" />

  10. Firas
    Member
    Posted 8 years ago #

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

  11. Jinsan
    Member
    Posted 8 years ago #

    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" } }

  12. Firas
    Member
    Posted 8 years ago #

    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.

  13. Jinsan
    Member
    Posted 8 years ago #

    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 ;)

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.