WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Images for list_cats (12 posts)

  1. Ryan Fitzer
    Member
    Posted 7 years ago #

    Is there a plugin that will provide a unique image for the list_cats tag? I want to have a page listing all of my categories with a unique image next to each one. I've seen the ones that use the_category but I need somthing simply for my archives page. Thanks.

  2. tsguitar
    Member
    Posted 7 years ago #

    Can you post the image in the category description? If you're not already using it, you could then call the description to show before each category in the list. See what I mean?

    And what do you mean by "for my archives page"?

  3. Ryan Fitzer
    Member
    Posted 7 years ago #

    That sounds like a great idea. I'm assuming that the description text area accepts images. I never knew this.

    By archives page I meant how all of the categories are listed in an unordered list on most themes. Just trying to be as descriptive as possible.

    I'll give this a try.

  4. tsguitar
    Member
    Posted 7 years ago #

    Do you want a unique image next to each post in the category or one unique image per category? I don't know if the description area accepts images, but I guess you'll be the test of that.

    If you're talking about displaying an image at the top of each category page, a different image for each category, you can use conditional tags to determine which category the page is a list of. This might help, too:
    http://codex.wordpress.org/Category_Templates#Different_Sticky_Text_on_Each_Category_Page

  5. Ryan Fitzer
    Member
    Posted 7 years ago #

    Tried to use the description box but quickly realized it's only for the title attribute when one rolls over the link.

    He's a better idea of what I would like to do. Lets say I had a category named "Friends". Then I would put all of my friends names as subcategories like so:

    Friends
    -John
    -Bob
    -Henry
    -Sally
    -Cindy

    What I would like to do is have a picture of each friend to the left of their name. Then when you clicked on the parent category of "Friends" you would be see a list of all my friends with their pic next to their name. When you click on the pic or their name you would be taken to all the posts about them.

    I know how to do everything except get the image in there.

    I know the above example is super corny. It's not actually what I'm doing but it works well for the description. The site will be a database of artists.

  6. tsguitar
    Member
    Posted 7 years ago #

    Well, I'm sure that if you put this in the right place, it'll return the category description for each subcategory:
    <?php echo category_description($cat->cat_ID); ?>

    You can use the category description however you wish. There's no rule that says it must be the title attribute. Your template can put that information anywhere. Just in case it helps, here's something that will return the category ID for each category associated with the current page:
    <?php foreach((get_the_category()) as $cat) {
    echo $cat->cat_ID . ' ';
    } ?>

    The problem is that the description field won't support image tags. It'll do other HTML, though. Give these a shot:
    http://www.coffee2code.com/archives/2004/06/27/plugin-category-images/
    http://devcorner.georgievi.net/wp-plugins/wp-category-icons/

  7. Ryan Fitzer
    Member
    Posted 7 years ago #

    Thanks for the help. I have checked out both of those plugins and from what I understand, the coffee2code is used to replace the_category.

    The devcorner one is a bit of a mystery to me as I can not figure out how to use it. The documentation is very confusing. I don't think it will work in the way I need either.

    Both seem to be used for individual posts rather than the full listing of all categories. Thanks for all your help though. I'll keep on looking.

  8. vicar
    Member
    Posted 7 years ago #

    Hey, ryanfitzer, did you ever figure out how to put a picture with each category title in the sidebar, ie a photo of each friend you listed? I want to do something similar with my category titles. Thanks!

  9. Ryan Fitzer
    Member
    Posted 7 years ago #

    Yeah. I had a plugin written to do the job. I'll get a link to it when I get back to the machine it's on. Check back.

  10. Ryan Fitzer
    Member
    Posted 7 years ago #

    Sorry it took so long. Here's the plugin Vipers Category Icons. Replace the .txt with .php in the file name, drop it in your plugins folder and activate it.

    Instructions on Usage:

    • Create a directory in wp-content named catimages
    • Name your images exactly the same name as the categories you want them to appear next to (if the category is News than name the image news.jpg) and drop them in the directory you created
    • The <img> element is given the class of catimage for styling

    Go nuts and give thanks the kind Mr. Viper007Bond.

  11. Ryan Fitzer
    Member
    Posted 7 years ago #

    The only caveat of this plugin is that it filters both list_cats as well as wp_list_cats. If you want to use one or the other without the images somewhere on your site than this may not be for you. I'm looking into this to see if it can be altered to do just one or the other so one could use wp_list_cats in the standard way and list_cats when images are needed.

    The codex has led me to believe that filtering list_cats will always extend to wp_list_cats. Anyone have any ideas on how to just filter one or the other?

  12. Ryan Fitzer
    Member
    Posted 7 years ago #

    I've updated the plugin link above with a newer version (thanks Viper007Bond) that allows you to define when you want list_cats or wp_list-cats to use images. Basically, you need to put <?php global $use_caticons; $use_caticons = TRUE; ?> before the instance of (wp_)list_cats where images are required. Here is an example:

    <?php global $use_caticons; $use_caticons = TRUE; ?>
    <ul>
    <?php wp_list_cats('sort_column=ID&hide_empty=0'); ?>
    </ul>

    Once I have a site up with this functionality I'll post a link here for those that aren't understanding what this plugin does.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags