2017-06-06 67 views
0

我試圖用自定義分類來隱藏自定義文章中的「Gyming」類別。試圖很難得到結果,但不幸的是它沒有與以下代碼一起工作。刪除Wordpress中的特定類別

function cat_subcat(){ 
$thetax = 'product'; 
    $args = array(
     'taxonomy' => 'product', 
     //'parent' => 0, 
     'hierarchical'=>true, 
     'order'=> 'ASC', 
     'show_count'=>false, 
     'show_option_all'=>'', 
     'child_of'=>0, 
     'depth'=>3, 
     'title_li'=>'', 
     'show_option_none' => __('No categories'), 
    ); 
echo '<ul class="category">'; 
    wp_list_categories($args); 
echo '</ul>'; 

}

善意的建議。

回答

0

如果您想從已創建的列表中排除某個類別,則可以將exclude添加到您的參數中,其中的值是您希望排除的類別的ID數組。因此,如果您想排除「Gyming」類別,您首先必須找到該類別的ID。如果你不知道如何找到ID,請使用以下指南https://www.wpwhitesecurity.com/wordpress-tutorial/find-wordpress-category-id/

如果ID是42,你的新代碼將

function cat_subcat(){ 
$thetax = 'product'; 
    $args = array(
     'taxonomy' => 'product', 
     //'parent' => 0, 
     'hierarchical'=>true, 
     'order'=> 'ASC', 
     'show_count'=>false, 
     'show_option_all'=>'', 
     'child_of'=>0, 
     'depth'=>3, 
     'title_li'=>'', 
     'show_option_none' => __('No categories'), 
     'exclude' => array(42), 
    ); 
echo '<ul class="category">'; 
    wp_list_categories($args); 
echo '</ul>'; 
} 
+0

我的類別ID爲8個,不包括行被添加,但仍其展示'Gyming'類別。 –

+0

https://muhammadisteel.com.pk/product/cooking-line/ –

+0

它完成了。謝謝你的協助。 –