Menu

WP e-Commerce Category Product List Shortcode

While setting up a store using WP e-Commerce I noticed that the Category Product List Shortcode was no longer working for me.

I cooked up a quick shortcode function using some of their product list code that will query the products by the passed category and output them using the product template.

First, place the following code in my_theme/functions.php:

function my_wpsc_products_shortcode($atts) {
	$number_per_page = get_option('use_pagination') ? get_option('wpsc_products_per_page') : 0;
	$query = shortcode_atts(array(
		'category_id' => isset($atts['cat']) ? $atts['cat'] : 0,
		'limit_of_items' => 0,
		'sort_order' => null,
		'number_per_page' => $number_per_page,
		'page' => 0,
	), $atts);

	return wpsc_display_products_page($query);
}
add_shortcode('my_wpsc_category', 'my_wpsc_products_shortcode');

Once that’s done you’ll be able to use [my_wpsc_category cat=6 /], where 6 is the integer ID of the category, on whichever page you want the products displayed on.

This list will be output using the wpsc-single_product.php template or the wpsc-products_page.php template, depending on whether you have multiple products in the category.

Feel free to ask questions in the comments.

Facebook Comments