Display categories as image blocks
-
Hi everyone,
I am trying to display my WordPress categories as tiled images – the image coming from the most recent article’s featured image. The image will then link to the category.
The image is showing fine, but the link to the category page doesn’t work…
PHP Code:
<?php $category = get_the_category(); if($category[0]){ $link = get_category_link($category[0]->term_id ); $cat_name = $category[0]->cat_name; $thumbnail = the_post_thumbnail('thumbnail'); echo "<a href='$link'>"; echo $cat_name; echo $thumbnail; echo '</a>'; } ?>
This code outputs the following code:
HTML Code:
<img width="226" height="185" src="IMAGE URL" class="attachment-thumbnail wp-post-image" /><a href="CATEGORY URL">Category</a>
Category Name
What I wanted was the following output:HTML Code:
<a href="CATEGORY URL">Category Name <img width="226" height="185" src="IMAGE URL" class="attachment-thumbnail wp-post-image" /></a>
Any ideas?
Thanks,
Simon
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Display categories as image blocks’ is closed to new replies.