【发布时间】:2015-03-19 17:55:33
【问题描述】:
我使用 woocommerce 作为目录。我想从类别 id 给每个产品类别的 css id。因为我想在某个地方制作“display:none”。
我在 Chrome 控制台中的代码如下所示:
<div class="woo-category">
<span>
<a href="http://www.yazicimakina.com.tr/?product_cat=overlap" rel="tag">Overlap</a>
","
<a href="http://www.yazicimakina.com.tr/?product_cat=tam" rel="tag">TAM</a>
","
<a href="http://www.yazicimakina.com.tr/?product_cat=tumu" rel="tag">TÜMÜ</a>
</span>
</div>
我的 PHP 代码:
<div class="woo-category">
<?php
$postid = get_the_ID();
$categories = get_the_term_list($postid, 'product_cat', '', ', ', '');
?>
<span><?php print_r($categories); ?></span>
</div>
我想:
<div class="woo-category">
<span>
<a id="example1" href="http://www.yazicimakina.com.tr/?product_cat=overlap" rel="tag">Overlap</a>
","
<a id="example2" href="http://www.yazicimakina.com.tr/?product_cat=tam" rel="tag">TAM</a>
","
<a id="example3" href="http://www.yazicimakina.com.tr/?product_cat=tumu" rel="tag">TÜMÜ</a>
</span>
</div>
我认为方法是:打印到类别 id 作为 css id,但我不知道如何在 PHP 中做到这一点。
【问题讨论】:
-
答案在 get_the_term_list() 函数中
标签: php css wordpress woocommerce