如何在 WP 电子商务插件中获取相对于产品 ID 的类别名称

发布于 2024-11-06 07:45:27 字数 365 浏览 1 评论 0原文

我正在使用 WP eCommerce 在我的网站中显示产品。我想检查页面中显示的每个产品的类别名称。

    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;

是否可以?

请帮我

I am using WP eCommerce for displaying products in my website.I want to check the category name of each product displaying in the page.

    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;

Is it possible?

Please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾铮苏瑾 2024-11-13 07:45:27

我研究了 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/罗汉

I looked into the bredcrumbs class and that helped me find a solution to a very similar problem that I had. Anyway, paste this code in and it will print out the category name for you.

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();

Hope this helps. I will be exploring this a bit more and will put up my results on my blog, http://www.consofas.com/

Rohan.

时光清浅 2024-11-13 07:45:27

我记得,它们存储为帖子,因此您可以使用普通的类别 api。 get_the_category(),我突然想到,应该会产生术语列表。

Best I recollect, they're stored as posts, so you can use the normal category api. get_the_category(), off the top of my head, should yield the list of terms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文