在 Woocommerce 中显示带有链接的产品标签列表 [英] Display the product tag list with links in Woocommerce

查看:42
本文介绍了在 Woocommerce 中显示带有链接的产品标签列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做与此代码相同的事情,但对于 woocommerce 中的产品标签:

<?php $tags = get_tags();?><div class="tags"><?php foreach ( $tags as $tag ) { ?><a href="<?php echo get_tag_link( $tag->term_id ); ?> " rel="tag"><?php echo $tag->name;?></a><?php } ?>

我还没有找到方法.

感谢任何帮助.

解决方案

Woocommerce 产品标签是一种自定义分类法.

因此您将使用 WordPress get_terms()get_term_link() 函数来代替:

 'product_tag', 'hide_empty' => false));?><div class="product-tags"><?php foreach ( $terms as $term ) { ?><a href="<?php echo get_term_link( $term->term_id, 'product_tag' ); ?> " rel="tag"><?php echo $term->name;?></a><?php } ?>

代码已经过测试并且可以正常工作.

<小时><块引用>

注意:对于产品类别,分类是'product_cat'而不是'product_tag'...

I would like to do the same thing as this code does, but for product tags in woocommerce:

<?php $tags = get_tags(); ?>
<div class="tags">
<?php foreach ( $tags as $tag ) { ?>
    <a href="<?php echo get_tag_link( $tag->term_id ); ?> " rel="tag"><?php echo $tag->name; ?></a>
<?php } ?>
</div>

I haven't found yet the way to do it.

Any help is appreciated.

解决方案

Woocommerce Product Tags are a custom taxonomy.

So you will use instead WordPress get_terms() and get_term_link() functions this way:

<?php $terms = get_terms(array('taxonomy' => 'product_tag', 'hide_empty' => false)); ?>
<div class="product-tags">
<?php foreach ( $terms as $term ) { ?>
    <a href="<?php echo get_term_link( $term->term_id, 'product_tag' ); ?> " rel="tag"><?php echo $term->name; ?></a>
<?php } ?>
</div>

Code is tested and works.


Note: For product categories, the taxonomy is 'product_cat' instead of 'product_tag'

这篇关于在 Woocommerce 中显示带有链接的产品标签列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆