Post navigation

code snippets

WPecommerce hack for showing category images

Cobbled together this bit of code for a WordPress template file to get the Categories from the database and show the images with their titles and links.

		<div id="cat-box-wrap">
		<?php
		global $wpdb, $wpsc_query;
		$sql = "SELECT `id`,`name`,`nice-name`,`image`,`description` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active` = 1 ORDER BY id ASC";
		$lists = $wpdb->get_results($sql,ARRAY_A);
		foreach ($lists as $list) :
		$catName = $list['name'];
		$catID = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE name = '$catName'");
		$imageURL = $wpdb->get_var("SELECT meta_value FROM `" . $wpdb->prefix . "wpsc_meta` WHERE `object_id` = '$catID'");
		?>
			<div class="cat-box">
            			<div class="cat-image">
                			<a href="<?php echo bloginfo('url').'/'.$list['nice-name']; ?>">
            				<img src="<?php echo bloginfo('url').'/wp-content/uploads/wpsc/category_images/'.$imageURL; ?>" />
                		</div><!-- /.cat-image -->
                		<div class="cat-title">
					<?php echo $list['name']; ?></a>
                		</div><!-- /.cat-title -->
           		</div><!-- /.cat-box -->
   		<?php endforeach; ?>
    		</div><!-- /#cat-box-wrap -->

Let me know if you have a better/smarter/smaller way of doing the same thing!

Leave a Reply

Your email address will not be published. Required fields are marked *

Please enable javascript to post a comment !