删除Wordpress中的特定类别
问题描述:
我试图用自定义分类来隐藏自定义文章中的“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>';
}
善意的建议。
答
如果您想从已创建的列表中排除某个类别,则可以将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>';
}
我的类别ID为8个,不包括行被添加,但仍其展示'Gyming'类别。 –
https://muhammadisteel.com.pk/product/cooking-line/ –
它完成了。谢谢你的协助。 –