Two images per category at wordpress

Is it possible to add multiple images for a category in wordpress?

I’ve seen this plugin that allows you to add a single image per category.

Read More

I would actually like to add 2 images per category. One for its header, and another one for its menu thumbnail.

Any recommendation?

Related posts

2 comments

  1. Yes, it can be done.
    One way is a bit long, and it involves

    1. assigning categories and taxonomies to attachments;
    2. querying media files by taxonomy so you can output them in a custom
      loop;
    3. using special taxonomy queries for images to display them on archive pages;
    4. adding an image to a category or taxonomy term as the category image.

    .. it would require a very long answer.

    But – there is a hack that would help you do it, although not as dynamic as the above one. ( although – read below it can be made dynamic as well )

    what you do is basically put images with the category name like bananas.jpg, pears.jpg, apples.jpg, and then

    <img src="whatever/directory/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" /> 
    

    of course, in your case you would do bananas-head.jpg, pears-head.jpg, apples-head.jpg , and then bananas-footer.jpg, pears-footer.jpg, apples-footer.jpg etc etc.. you get the picture ( no pun intended ).

    Of course, like said before, it is not so dynamic, but it can easily be converted to one by using special theme settings, where one upload an image for each category, and the theme just grabs the category image by taxonomy ID …

Comments are closed.