类别-是否在默认设置后立即创建新的单独设置?

时间:2018-08-20 作者:Run

是否可以在默认类别集之后创建新的类别集?

例如,在WP admin区域,这是我们默认看到和得到的内容:

Pages
- All Pages
- Add New
- Categories
- Tags
我想为类别创建另一个集合,因此:

Pages
- All Pages
- Add New
- Categories
- My New Categories
- Tags
这可能吗?

1 个回复
最合适的回答,由SO网友:nmr 整理而成

创建自定义分类法时,请使用post 作为分类法的对象类型:

register_taxonomy(\'your_custom_taxonomy\', \'post\', $args);
新的自定义分类将显示在“Posts“标签”下的子菜单。要更改此顺序,请将此代码添加到functions.php 或插件文件):

add_filter(\'menu_order\', \'reorder_post_submenu\', 15);
function reorder_post_submenu($menu_order) {    
    global $submenu;

    if (isset($submenu, $submenu[\'edit.php\'])) {
        $i_offset = strlen(\'taxonomy=\');
        $tmp_order = false;
        foreach ($submenu[\'edit.php\'] as $key => &$value) {
            $i_txm = strpos($value[2], \'taxonomy=\');
            if ($i_txm === false)
                continue;
            $name = substr($value[2], $i_txm + $i_offset);
            if ($name == \'post_tag\' ) {
                // get last item key
                $last = array_pop( array_keys($submenu[\'edit.php\']) );
                // move "tag" menu item to the end
                $submenu[\'edit.php\'][$last + 5] = $value;
                unset($submenu[\'edit.php\'][$key]);
                break;
            }
        }
    }
    return $menu_order;
}
“默认帖子”子菜单如下所示:

[edit.php] => Array (
    // ["label", "capability", "page"] 
    [5] => Array (
            [0] => All Posts
            [1] => edit_posts
            [2] => edit.php
        )
    [10] => Array (
            [0] => Add New
            [1] => edit_posts
            [2] => post-new.php
        )
    [15] => Array (
            [0] => Categories
            [1] => manage_categories
            [2] => edit-tags.php?taxonomy=category
        )
    [16] => Array (
            [0] => Tags
            [1] => manage_post_tags
            [2] => edit-tags.php?taxonomy=post_tag
        )
)

结束

相关推荐

Media Library Categories

我使用以下内容将类别分配给我的WordPress媒体库(在functions.php):function wptp_add_categories_to_attachments() { register_taxonomy_for_object_type( \'category\', \'attachment\' ); } add_action( \'init\' , \'wptp_add_categories_to_attachments\' ); 每个媒体库项目都