Styling Categories using Images
-
First of all, thank you for looking at this post. I basically want to render all the categories on my home page (instead of posts) and style them with an image, category title, and the category link. This is something similar to what I’m looking for:
<?php foreach((get_the_category('child_of=16')) as $category) { echo '<div class="item"><div class="background"></div>'; echo '<a href="https://example.com/?cat=' . $category->cat_ID . '"> '; echo '<img src="https://example.com/images/' . $category->cat_ID . '.jpg" alt="' . $category->cat_name . '" />'; echo '</a>'; echo '<div class="content">'; echo '<h2>'; echo '<a href="https://example.com/?cat=' . $category->cat_ID . '"> '; echo $category->cat_name . ' '; echo '</a>'; echo '</h2>'; echo '</div></div>'; } ?>
Excuse me for all the echos, but I’m a beginner in php and wanted to take everything step by step. The only problem with the code above is that it has to be inside the Loop so it will only render categories of that post. But I want to render ALL the child categories of ID 16.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Styling Categories using Images’ is closed to new replies.