Wordpress 是否将类别名称作为div类?

Wordpress 是否将类别名称作为div类?,wordpress,class,woocommerce,Wordpress,Class,Woocommerce,好的,我正在尝试检索WoodPress循环中显示的woocommerce产品的类别名称,并将其用作循环中li的类。我也尝试了以下方法: <div id="isocontent" class="products"> <ul><?php while (have_posts()) : the_post(); ?> <li class="<?php echo $produ

好的,我正在尝试检索WoodPress循环中显示的woocommerce产品的类别名称,并将其用作循环中li的类。我也尝试了以下方法:

 <div id="isocontent" class="products">
                <ul><?php while (have_posts()) : the_post(); ?>


                        <li class="<?php echo $product->get_categories(); ?> box">
                            <a href="<?php the_permalink(); ?>"><?php echo the_post_thumbnail(); ?></a>
                            <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
                            <a href="<?php the_permalink(); ?>"><span href="<?php the_permalink(); ?> " class="amount price" data-original="<?php echo get_woocommerce_currency(); ?><?php echo $product->get_price(); ?>" data-price="<?php echo $product->get_price(); ?>" title="Original price: <?php echo $product->get_price(); ?>"><?php echo get_woocommerce_currency(); ?><?php echo $product->get_price(); ?></span></a>
                            <a href="<?php the_permalink(); ?>?add-to-cart=<?php echo $post->ID ?>" class="pbutton">Add to Cart</a>
                        </li>
                    <?php endwhile; ?>
                </ul>
            </div> 

但是由于woocommerce使用taxonmys,它检索标签,而不是产品类别。 任何帮助都是非常感激的 问候
Chris

这不像进行一次调用那么简单-
get_categories()
旨在显示产品类别的HTML表示。产品类别实际上是一个自定义的分类法,因此您必须使用它

global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
    $category_id = $term->term_id;
    $category_name = $term->name;
    $category_slug = $term->slug;
    break; 
}

它不像单个调用那么简单-
get_categories()
旨在显示产品类别的HTML表示。产品类别实际上是一个自定义的分类法,因此您必须使用它

global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
    $category_id = $term->term_id;
    $category_name = $term->name;
    $category_slug = $term->slug;
    break; 
}

我可以调整此选项以返回/taxonomy-product_cat.php页面上的子类别吗?如果产品是指定给子类别的,则默认情况下,它应该为您提供子类别。如果您想遍历,请检查:我是否可以调整此选项以返回/taxonomy-product_cat.php页面上的子类别?如果产品是指定给子类别的,则默认情况下它应该为您提供子类别。如果要遍历,请签出:
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
    $category_id = $term->term_id;
    $category_name = $term->name;
    $category_slug = $term->slug;
    break; 
}