Skip to content

Instantly share code, notes, and snippets.

@webonaut
Created April 4, 2015 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webonaut/fb0b5114c28f2cce9834 to your computer and use it in GitHub Desktop.
Save webonaut/fb0b5114c28f2cce9834 to your computer and use it in GitHub Desktop.
WooCommerce - Kategoriebild als Background-image anzeigen
// Beschreibung: Lädt das kategoriebild als background-image;
// Speicherort: In einem Kategorie- / Archiv-Template, z.B. in der archiv-product.php;
// Quelle: http://stackoverflow.com/questions/22537600/woocommerce-with-wordpress-how-can-i-display-category-image;
<?php
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
//if you only want the image, uncomment the two lines below
//list($width, $height) = getimagesize($image);
//echo '<img src="'.$image.'" alt="" width="'.$width.'" height="'.$height.'"/>';
$cat_id=$cat->term_id;
$prod_term=get_term($cat_id,'product_cat');
$description=$prod_term->description;
echo '<div id="kategoriebild" style="background-image: url('.$image.')"></div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment