【发布时间】:2013-11-24 20:28:49
【问题描述】:
我正在使用以下代码,放置在我的 Wordpress 主题的 functions.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', 10, 2);
问题是这段代码还在后端隐藏了这些相同的类别名称。复选框在那里,但类别的名称不存在。因此,我想修改此代码以允许管理员在后端查看隐藏在前端的类别的名称。帮助表示赞赏。 (ps,我对代码很陌生,所以请尽量描述性,或提出修改建议:非常感谢)
【问题讨论】:
标签: php wordpress categories