我找到了这个,它允许我为当前的产品页面显示逗号分隔的标签列表.
echo $product->get_tags( ', ', '<span>' . _n( '', '', $tag_count, 'woocommerce' ) . ' ', '</span>' );...which的输出如下:
<span>
<a href="http://example.com/product-tag/name-1/" rel="tag">Name 1</a>,
<a href="http://example.com/product-tag/name-2/" rel="tag">Name 2</a>
</span>但我实际上想要的是将URL中的/product/ part更改为其他内容,如下所示:
<span>
<a href="http://example.com/something-else/name-1/" rel="tag">Name 1</a>,
<a href="http://example.com/something-else/name-2/" rel="tag">Name 2</a
</span>任何帮助都会很好。
发布于 2015-12-14 01:38:59
基于对来自“雪花”的响应的稍微修改,这是可行的:
$terms = wp_get_post_terms( $product->id, 'product_tag');
foreach($terms as $term) {
echo '<a href="'. $term->slug .'">'.$term->name.'</a>';
}发布于 2015-12-11 09:14:03
您需要首先检索这些术语:
$terms = wp_get_post_terms( $product->id, 'product_cat');然后遍历这些术语:
foreach($terms as $term) {
echo '<a href="'. get_term_link($term->term_id).'">'.$term->name.'</a>';
}而不是get_term_link,您将不得不根据您的规则构建您的URL。
https://stackoverflow.com/questions/34218446
复制相似问题