I have a problem. I use a filter with thumbnails. At least this filter does not include get category thumbnail and you have to upload all thumbnails manually into the filter which is not a good solution.
What I try to do is to get the thumbnail automatically from the category thumbnail. So far I have a code which adds a thumbnail from the current query which is also not a good solution. I need to get the thumbnail for each category separately.
This code works with current query and display the same image for all categories from the current opened category. Do you have any idea how could I get thumbnail for each category separately?
if ( is_product_category() ){
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id using the queried category term_id
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
return '<span class="prdctfltr_customize_block prdctfltr_customize"><span class="prdctfltr_customize_image"><img src="' . $image . '" alt="' . $cat->name . '"/></span>' . ( $cnt !== false ? ' <span class="prdctfltr_customize_count">' . absint( $cnt ) . '</span>' : '' ) . ( $tip !== false ? '<span class="prdctfltr_tooltip"><span>' . wp_kses_post( $tip ) . '</span></span>' : '' ) . ( $checked !== '' ? '<input type="checkbox" value="' . esc_attr( $term_slug ) . '"' . esc_html( $checked ) . '/>' : '' ) . '<span class="prdctfltr_customization_search">' . esc_html( $term_name ) . '</span>' . wp_kses_post( $sublevel ) . '</span>';
}
Thank you in advance.
UPDATE
PHP CODE
My Answer:
>get_queried_object();__ // get the category thumbnail_ $thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );__ // display the thumbnail_ if ( $thumbnail_id ) {_ echo wp_get_attachment_image( $thumbnail_id, 'thumbnail' );_ }_}
Rate this post
3 of 5 based on 1794 votesComments