简体   繁体   English

在单个产品页面上的产品名称旁边显示类别名称

[英]Display category name next to product name on single product page

I'm trying to add the category name next to the product name on my woocommerce page.我正在尝试在我的 woocommerce 页面上的产品名称旁边添加类别名称。 I would like to displays it because of SEO reasons, so that Google knows that this product belongs to this category.因为SEO的原因我想把它展示出来,让谷歌知道这个产品属于这个类别。

My code looks like this at the moment我的代码目前看起来像这样

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

I tried to get it done by adding我试图通过添加来完成它

<?php echo wc_get_product_category_list($product->get_id()) ?>

but there is no category name and dev consolse etc also shows no errors.但是没有类别名称,开发控制台等也没有显示错误。

Instead try to replace your code with the following:而是尝试使用以下内容替换您的代码:

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;

It should work.它应该工作。

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

相关问题 在单个产品页面上显示类别和品牌名称 - Display category and brand name on single product page 在Woocommerce单一产品页面中获取产品类别名称和描述 - Get the product category name and description in Woocommerce Single Product page Woocommerce 在类别页面的产品名称旁边显示父类别 - Woocommerce show parent category next to product name on category page WooCommerce:如何在single-product.php中显示类别名称 - WooCommerce: How to display Category Name in single-product.php 在opencart 2.1.0.1产品页面中显示类别名称和链接不起作用 - Display category name and link in opencart 2.1.0.1 product page not work 在单个产品页面简码上显示产品类别 AFC 字段 - Display product category AFC field on Single product page shortcode 页面标题中包含的类别和产品名称标准 - Category and product name standard included in the page title 如何在Wordpress中的产品详细信息页面上获得产品的类别名称 - How to get the Category name of product on product detail page in wordpress 如何在magento中获取当前产品的类别名称(在产品详细信息页面上) - how to get category name of current product (on product detail page) in magento 显示带有产品类别 ID 的类别名称 - Laravel - Display Category Name With Category ID from Product - Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM