display image with category


I’m pretty new to wordpress theming, I’m making a website where you can see the list of categories of all the website. So I managed to show a list of all my categories by doing this:

$categories = get_categories();
foreach($categories as $category) {
   echo '<div class="category"><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></div>';

But just aside of that, I would like to have a list of images that are linked to these categories,
so in the exemple, I have a category called dogs with a few images of dog. I would like to be able to create new categories and link some images to it.

Can I have some help on how to do that? Maybe it’s not the recommended method?

I managed to add a field to my images where I can stand the category, now I need to display the images to the corresponding category.

function wptp_add_categories_to_attachments() {
   register_taxonomy_for_object_type( 'category', 'attachment' );
add_action( 'init' , 'wptp_add_categories_to_attachments' );

now my images have a category, I just need to display them in the index.php

pual 2 months 0 Answers 7 views 0

Leave an answer