【发布时间】:2017-11-20 21:33:42
【问题描述】:
我一直在使用产品标签作为商店中产品的品牌。我在网上找到的以下代码一直运行良好(直到最近更新了 woocommerce 和 WP),以便在我的“品牌”页面上列出一个列表。它列出了每个特定类别字母下的所有品牌。
突然没有生成任何 URL,其他所有内容都按应有的方式填充。我真的找不到问题。我尝试将get_terms 修改为get_terms(array('taxonomy'=>'product_tag')),但它也不起作用。
这是我的代码:
$list = '';
$tags = get_terms( 'product_tag' );
$groups = array();
if( $tags && is_array( $tags ) ) {
foreach( $tags as $tag ) {
$first_letter = strtoupper( $tag->name[0] );
$groups[ $first_letter ][] = $tag;
}
if( !empty( $groups ) ) {
foreach( $groups as $letter => $tags ) {
$list .= "\n\t" . '<div class="brand_category_container">';
$list .= "\n\t" . '<h4 class="cateogry_letter">' . apply_filters( 'the_title', $letter ) . '</h2>';
$list .= "\n\t" . '<ul>';
foreach( $tags as $tag ) {
$url = get_tag_link( $tag->term_id );
$count = intval( $tag->count );
$name = apply_filters( 'the_title', $tag->name );
$list .= "\n\t\t" . '<li><a class="category_links" href="' . $url . '">' . $name . '</a></li>';
}
$list .= "\n\t" . '</ul></li>';
$list .= "\n\t" . '</div>';
}
}
} else $list .= "\n\t" . '<p>Sorry, but no tags were found</p>';
在我的产品页面上,我列出了品牌
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
?>
<div class="single_productbrand">
<?php echo $product->get_tags( ', ', '<span class="brand_as">' . _n( '', '', $tag_count, 'woocommerce' ) . ' ', '</span>' ); ?>
</div>
它可以正常工作
如何取回网址?
【问题讨论】:
-
var_dump($tags); 的输出是什么?
标签: php wordpress woocommerce tags taxonomy