2011-05-10 82 views
0

我正在使用WP电子商务在我的网站上显示产品。我想检查每个产品在页面中显示的类别名称。如何在WP电子商务插件中获取产品ID的类别名称

while (wpsc_have_products()) : wpsc_the_product(); 
      $product_id=wpsc_the_product_id(); 
     //here I want to get the category name with respect to $product_id in which this product exists. 

      my code continues... 

    endwhile; 

这可能吗?

请帮我

回答

0

最佳我记得,他们在存储帖子,这样你就可以使用正常的类API。我的头顶上写着get_the_category(),应该列出条款清单。

1

我看着bredcrumbs类,这帮助我找到了解决我遇到的一个非常类似的问题。无论如何,粘贴此代码,它会打印出你的类别名称。

function cdl_get_cat() { 
global $wp_query, $wpsc_query; 
$query_data = Array(); 
$cdl_post_id = wpsc_the_product_id(); 

$categories = wp_get_object_terms($cdl_post_id , 'wpsc_product_category'); 
//if product is associated w more than one category 
if(count($categories) > 1 && isset($wpsc_query->query_vars['wpsc_product_category'])) 
    $query_data['category'] = $wpsc_query->query_vars['wpsc_product_category']; 
elseif(count($categories) > 0) 
    $query_data['category'] = $categories[0]->slug; 

return $query_data['category']; 
} 
echo cdl_get_cat(); 

希望这会有所帮助。我将探索这一点,并将在我的博客上张贴我的结果,http://www.consofas.com/

Rohan。

+0

不,它只输出slu。。你如何输出名称? – 2013-01-10 10:51:30

+0

迪伦,你所要做的就是把'$ categories [0] - > slug'改成'$ categories [0] - > name''。但是有一个问题;如果产品与多个类别(例如类型/性别/等)相关联,它将检索最近添加的适用类别,这可能不一定是您希望显示的类别(我讨厌WP电子商务)...将保留你更新了。 – zillaofthegods 2013-01-22 14:58:32

相关问题