Trying to add cat_ID to array for showing an image for specific Category

So OK….I might be way of but here goes.
Im using a plugin that gives the post a Featured Image if its not set. So Im trying to make it that depending on in which category the post is in the Featured Image should correspond to the category.

So this is the code om trying to mend.

Read More
<?php get_the_image( array( 'meta_key' => 'feature_img', 'size' => 'medium', 'width' => '300', 'height' => '170', 'image_class' => 'feature', 'default_image' => 'http://www...../uploads/img_cat_' . $category->cat_ID . '.jpg' ) ); ?>

Its the ” ‘ . $category->cat_ID . ‘ ” code Im not sure about .

I want the JPG displayed img_cat_4.jpg if the post belongs to Cat nr 4 etc.

Any takers?

Related posts

Leave a Reply

1 comment

  1. I have not used that plug-in but I would guess that your function get_the_image() doesn’t accept that parameter as part of the array.

    I would first check for that custom function to be active. If you turn that plug-in off you will get an error on your page:

    <?php if ( function_exists( 'get_the_image' ) ) { get_the_image(); } ?>
    

    Then just insert your parameters as above.

    You can try this (untested) is this in the loop? if not this might not work for you.

    <?php 
    $category = get_the_category(); 
    if ( function_exists( 'get_the_image' ) ) get_the_image( array( 'meta_key' => 'feature_img', 'size' => 'medium', 'width' => '300', 'height' => '170', 'image_class' => 'feature', 'default_image' => 'http://www...../uploads/img_cat_' . $category[0]->cat_name . '.jpg' ) ); 
    ?>