I want to display placeholder image if there is no category image and no featured image for a post
Then if there is a category image display then instead
Then if there is a featured image for a post display this instead
<?php if (has_post_thumbnail()) { ?>
<img src="<?php echo the_post_thumbnail_url(); ?>" class="single-blog-post-image" alt="Post Featured Image" />
<?php } else {
$category = get_the_category();
$categoryImage = 'http://akjservices.foamydev.com/wp-content/uploads/'.$category[0]->category_nicename.'.png';
if (!has_post_thumbnail() && file_exists($categoryImage)) {
?>
<img class="single-blog-post-image" src="<?php bloginfo('url'); ?>/wp-content/uploads/<?php echo $category[0]->category_nicename ; ?>.png" alt="Category Featured Image" />
<?php } else { ?>
<img src="/wp-content/themes/akj/img/placeholder-part-image.jpg" alt="AKJ Services Default Image" class="single-blog-post-image">
<?php } }?>
It is working apart from it only gets the category image from the very first category nothing else
How can I amend my code to fix it so I can get any post category image?
Can see an example here
http://akjservices.foamydev.com/product/fr-sfj-2-7-5k/ => default placeholder image
The code specifies that the image name must be the same as the category name for example A06B-6044.png - however happy to ignore this and for it just to show the category image no matter what the name is.