简体   繁体   English

如何在WP eCommerce插件中获取有关产品ID的类别名称

[英]how to get category name with respect to product id in WP eCommerce plugin

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. 我正在使用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;

Is it possible? 可能吗?

Please help me 请帮我

I looked into the bredcrumbs class and that helped me find a solution to a very similar problem that I had. 我调查了bredcrumbs类,这帮助我找到了解决我所遇到的非常相似问题的解决方案。 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/ 我将对此进行更多探索,并将结果发表在我的博客http://www.consofas.com/上

Rohan. 罗汉

Best I recollect, they're stored as posts, so you can use the normal category api. 最好的回忆是,它们存储为帖子,因此您可以使用常规类别api。 get_the_category() , off the top of my head, should yield the list of terms. get_the_category()不在我的脑海,应该产生术语列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Wordpress中的产品类别名称获取CSS ID - How to get css ID from product category name in Wordpress 如何在Solr响应中获取类别名称和product_id - How to Get Category name along with product_id in Solr response 获取产品类别上 wp_Query 的类别名称/slug 以根据类别显示产品列表 - Get Category name/slug for wp_Query on product-category to show product list according to category 如何在电子商务产品 URL 中使用名称而不是参数化 ID - How to use Name in Ecommerce Product URL instead of parametrized ID 如何在wordpress电子商务插件中加入wp_posts和wp_postmeta仅检索产品标题,产品描述和价格? - How to join wp_posts and wp_postmeta in wordpress ecommerce plugin retrieving only product title, product description and price? WP REST API - 在发布请求时获取类别名称而不是 id - WP REST API - Get category name instead of id on post request 使用产品 ID 或类别 ID 从 WooCommerce 产品中获取类别名称 - Get the category name from a WooCommerce product using the product id or the category id 如何在woocommerce中获取当前产品类别名称 - how to get current product category name in woocommerce 从WP获取类别ID - Get category ID from WP Magento-从产品ID获取特定的类别名称 - Magento - get specific category name from product id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM