【问题标题】:Display category name next to product name on single product page在单个产品页面上的产品名称旁边显示类别名称
【发布时间】:2019-08-09 01:04:53
【问题描述】:

我正在尝试在我的 woocommerce 页面上的产品名称旁边添加类别名称。由于SEO原因,我想展示它,以便Google知道该产品属于该类别。

我的代码现在是这样的

 the_title( '<h1 class="product_title entry-title">', '</h1>  <?php echo wc_get_product_category_list($product->get_id()) ?>'  );

我试图通过添加来完成它

&lt;?php echo wc_get_product_category_list($product-&gt;get_id()) ?&gt;

但没有类别名称,开发控制台等也没有显示错误。

【问题讨论】:

    标签: php wordpress woocommerce product taxonomy-terms


    【解决方案1】:

    尝试用以下代码替换您的代码:

    the_title( '<h1 class="product_title entry-title">', '</h1>' ); 
    $terms = wp_get_post_terms( get_the_id(), 'product_cat' );
    $term  = reset($terms);
    echo $term->name;
    

    它应该可以工作。

    【讨论】:

    • 您好,通过添加此代码,它会隐藏产品名称并仅显示类别,作为面包屑,它应该只是产品名称活动类别。 s16.directupload.net/images/190318/66jthrsf.png
    • @p_e_88 做了一个只显示第一个产品类别的更新……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 2018-12-10
    相关资源
    最近更新 更多