我正在使用woocommerce作爲目錄。我想給類別ID的每個產品類別的CSS ID。因爲我想在某些地方製作「display:none」。如何在Wordpress中從產品類別名稱獲取css ID
我看的代碼在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某處()函數 – 2015-01-21 09:19:14