2017-04-27 14 views
0

我想獲得第三級WooCommerce類別下面第三級分類是我的代碼:獲取WooCommerce

$args = array(
     'hierarchical' => 1, 
     'show_option_none' => '', 
     'hide_empty' => 0, 
     'parent' =>18, 
     'taxonomy' => 'product_cat' 
    ); 
    $subcats = get_categories($args); 
    echo '<div class="wooc_sclist">'; 
    foreach ($subcats as $sc) { 
     $link = get_term_link($sc->slug, $sc->taxonomy); 
     echo '<ul><a href="' . $link . '">' . $sc->name . '</a></ul>'; 
    } 
    echo '</div>'; 
    wp_reset_query(); 

回答

0

我解決它

 $args = array(
    'hierarchical' => 1, 
    'show_option_none' => '', 
    'hide_empty' => 0, 
    'parent' => $number = 16, 
    'taxonomy' => 'product_cat' 
); 
$subcats = get_categories($args); 
echo '<div class="wooc_sclist">'; 
foreach ($subcats as $sc) { 
    $link = get_term_link($sc->slug, $sc->taxonomy); 
    echo '<ul><a href="' . $link . '">' . $sc->name . '</a>'.$sc->term_id; 
    $args2 = get_terms('product_cat',array(
     'child_of' => $sc->term_id, 
     'hierarchical' => 1, 
     'hide_empty' => 1, 
    )); 
    foreach ($args2 as $subsubCats) { 
     $SubLinks = get_term_link($subsubCats->slug, $subsubCats->taxonomy); 
     echo '<li>sub - <a href=' . $SubLinks . '>' . $subsubCats->name . '</a></li>'; 
    } 
    echo '</ul>'; 
} 
echo '</div>'; 
wp_reset_query(); 
+0

你在哪裏粘貼? – sven30

+0

我爲這裏的下拉菜單創建一個自定義菜單WordPress的鏈接[鏈接](http://knproducts.com.pk) –