在目录页面上显示标签 woo commerce - wordpress [英] display tags on catalogue pages woo commerce - wordpress

查看:34
本文介绍了在目录页面上显示标签 woo commerce - wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一种方法可以使用 woocommerce(wordpress 插件)在目录页面上显示产品的标签,我看起来像个疯子.我找不到任何关于 ti 的信息,我一直在尝试调整代码,但没有成功...

I'm looking like a crazy person if there is a way to display the tags of a product on the catalogue page with woocommerce ( wordpress plugin). I can not find anything about ti and I've been trying to tweak the code, but without success . . .

如果有人有一些high lite,那就太好了,

if anybody has some high lite, it will be wonderful,

非常感谢

推荐答案

此示例将在商店存档页面上显示产品标签.代码取自单个产品元模板 ( single-product/meta.php ),因此 HTML 将与单个产品页面中的相同.该函数与 woocommerce_after_shop_loop_item 操作挂钩(标签将位于主要内容和 add_to_cart 内容之间),如果您想将它们放在其他地方,请打开 content-product.phpwc-template-hooks.php 插件文件,以查看附加功能的所有可用操作和优先级,并将 woocommerce_product_loop_tags 功能附加到不同的操作.

This example will show product tags on shop archive pages. The code is taken from the single product meta template ( single-product/meta.php ), so HTML will be the same as in single product pages. The function is hooked to woocommerce_after_shop_loop_item action ( the tags will be between the main content and the add_to_cart content ), if you want to place them elsewhere open the content-product.php and wc-template-hooks.php plugin files, to see all the available actions and priorities of functions attached, and attach woocommerce_product_loop_tags function to a different action.

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_loop_tags', 5 );

function woocommerce_product_loop_tags() {
    global $post, $product;

    $tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );

    echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}

这篇关于在目录页面上显示标签 woo commerce - wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆