Created
April 4, 2015 10:10
-
-
Save webonaut/fb0b5114c28f2cce9834 to your computer and use it in GitHub Desktop.
WooCommerce - Kategoriebild als Background-image anzeigen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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