Basically I want to incorporate the category id in the following code:
<?php
$category = wp_list_categories('style=none&echo=0&child_of=4&depth=1&title_li=');
$category = preg_replace('/(<a)/','<div class="item"><div class="background"></div><a href="https://example.com/?cat=' . CATEGORY ID . '"><img src="https://example.com/images/' . CATEGORY ID . '" alt="' . $category->cat_name . '" /></a><div class="content"><h2><a',$category);
$category = str_replace('</a>', '</a></h2></div></div>', $category);
echo $category;
?>
I’m using this code on the index.php outside of the Loop and want to display the categories with the specified style and an image where the image will be from the url https://example.com/images/CATIDHERE . So, each category has its own thumbnail image linking to the category.php.
Using $category->cat_id
doesn’t work. I’ve also tried $wp_query->get_queried_object_id but when I use that, the category ID would be the same for all categories (I don’t know why) and so the thumbnail would become the same for the different categories.
Please help.