I am using wp-ecommerce plugin to create a shopping cart in WordPress.
If I am on this URL, it displays all the products in services wpsc-product-category.
http://localhost/wordpress/products-page/services/
How can I get the wpsc-product-category id in the page template.
I have many categories as shown above and every category has different menu on page.php template.
I need to get category id or category slug to show different menu for different categories
After searching whole day on google I could find this:
<?php
if(is_category())
{
$cat = get_query_var(âcatâ);
$yourcat = get_category($cat);
echo $yourcat->slug;
}
else
{
echo âCountryâ; //default one
}
?>
But it does not work on page.php template.
I created my own logic and it worked for me. Pasting my code here, hoping it might help someone else:
if(wpsc_display_products()):
if(wpsc_is_in_category()) :
if(wpsc_category_id() == 89 ||
wpsc_category_id() == 66 ||
wpsc_category_id() == 62 ||
wpsc_category_id() == 61)
{
$menu = "menu1";
}else
{
$menu = "menu2";
}
endif;
endif;
Did you ever figure this out? I was able to do this with jQuery actually. Just make a separate widget for each category then in your js write something like this:
Just continue down with
else if
statements for each category. It could be a lot of code if you have a lot of categories but it did the trick for me. It just runs through all the classes on the body and if it contains the category name in any class it adds the category name as a class of it’s own.I too have been searching on how to do basically anything with WPeC functions outside of their template files, and I ran across this site here:
Category wise products display in WP E-Commerce products page
I believe there are a couple of coding errors in the example he provides but you can see where he can get the category ID here:
I’ve used his code and built on it a little for my website’s purpose (within the
page.php
template) which you can look at if you’d like to.https://gist.github.com/4553667