我在函数中使用以下代码。我的主题的php,隐藏用于组织帖子的特定类别,并从帖子本身及其类别列表填充滑块:
function the_category_filter($thelist,$separator=\' \') {
// list the IDs of the categories to exclude
$exclude = array(1,32,42,4);
// create an empty array
$exclude2 = array();
// loop through the excluded IDs and get their actual names
foreach($exclude as $c) {
// store the names in the second array
$exclude2[] = get_cat_name($c);
}
// get the list of categories for the current post
$cats = explode($separator,$thelist);
// create another empty array
$newlist = array();
foreach($cats as $cat) {
// remove the tags from each category
$catname = trim(strip_tags($cat));
// check against the excluded categories
if(!in_array($catname,$exclude2))
// if not in that list, add to the new array
$newlist[] = $cat;
}
// return the new, shortened list
return implode($separator,$newlist);
}
// add the filter to \'the_category\' tag
add_filter(\'the_category\',\'the_category_filter\', 1, 32, 42, 4);
这很好,但它也隐藏了后期编辑后端中的类别。我可以看到勾选框,但类别名称已隐藏。
是否有人可以建议对上述代码进行调整,以保留其在前端隐藏类别的功能,但保持类别在编辑后窗口/WP后端可见?