php WooCommerce:显示类别名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26746545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WooCommerce: Display Category Name
提问by realph
Is there a way to display the product category name on the WooCommerce archive-product.php
page. My product category name is "Bracelets", and I'd like that to be displayed as a title on the page. I'm using wp_title()
currently:
有没有办法在 WooCommercearchive-product.php
页面上显示产品类别名称。我的产品类别名称是“手镯”,我希望将其作为标题显示在页面上。我wp_title()
目前正在使用:
<h1><?php wp_title(); ?></h1>
But that prints it to the page like this:
但这会像这样将其打印到页面上:
? Product Categories ? Bracelets
I'm getting the parent page title and the catgeory name with separators in between them (above). Is there any way I can get the title to print just "Bracelets"?
我得到了父页面标题和类别名称,它们之间有分隔符(上图)。有什么办法可以让标题只打印“手镯”?
Any help with this is appreciated.
对此的任何帮助表示赞赏。
Thanks in advance!
提前致谢!
回答by diggy
You're looking for single_term_title()
: http://codex.wordpress.org/Function_Reference/single_term_title
您正在寻找single_term_title()
:http: //codex.wordpress.org/Function_Reference/single_term_title
回答by Igor Okto
回答by Swapnali
Use the get_categoriesfunction to retrieve categories name :-
使用get_categories函数检索类别名称:-
You can use this code to display product categories name -
您可以使用此代码显示产品类别名称 -
<?php global $post, $product;
$categ = $product->get_categories();
echo $categ; ?>
回答by cesare
I think it prints the breadcrumb, because it's hooked woocommerce_breadcrumb.
我认为它打印了面包屑,因为它上钩了 woocommerce_breadcrumb。
You could override in your theme the template Archive-product.php
您可以在主题中覆盖模板 Archive-product.php
<?php
/**
* woocommerce_before_main_content hook
*
*/
do_action( 'my_woocommerce_before_main_content' );
?>
and create another action inside functions.php,
并在functions.php中创建另一个动作,
add_action( 'my_woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
add_action( 'my_woocommerce_before_main_content', 'my_woocommerce_print_category_name', 20 );
Inside your functions.php you can also create a functions like this:
在您的functions.php 中,您还可以创建这样的函数:
function my_woocommerce_print_category_name() {
//You can implements a function for get category name...
}