获取父类别链接

时间:2018-02-26 11:11:52

标签: wordpress

我正在尝试获取父类别链接 - 这是我的代码,但它似乎无法正常工作。

<?php
$taxonomyName = "equipment_categories";
$parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false));   
echo '<div class="subcats"><a class="subcatseach" href="' . $cat = get_the_category(); $cat = $cat[0]; echo get_category_link($cat->cat_ID) . '">All Equipment</a>';
foreach ($parent_terms as $pterm) {
    $terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false));
    foreach ($terms as $term) {
        echo '<a class="subcatseach" href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a>';  
    }
}
echo '</div>';

?> 

有什么建议吗?

0 个答案:

没有答案