如何在同一菜单位置(MENU_POSITION=20-Below Pages)中排序多个自定义POST类型?

时间:2020-05-20 作者:daily-learner

这些是我用来使用“menu\\u position”参数在“Master Artister Lookup”上方显示“Artists”的参数。但是,仍不能正确显示在菜单中

        $args = [
            \'label\'              => __(\'Artists\', SMF_CORE_NAME),
            \'labels\'             => [
                \'name\'          => __(\'Artists\', SMF_CORE_NAME),
                \'singular_name\' => __(\'Artist\'),
                \'add_new_item\'  => __(\'Add New Artist\', SMF_CORE_NAME),
                \'add_new\'       => __(\'Add New Artist\', SMF_CORE_NAME),
                \'new_item\'      => __(\'Add New Artist\', SMF_CORE_NAME),
                \'all_items\'     => __(\'All Artists\', SMF_CORE_NAME),
                \'edit_item\'     => __(\'Edit Artist\', SMF_CORE_NAME)
            ],
            \'supports\'           => [\'title\', \'thumbnail\'],
            \'hierarchical\'       => false,
            \'public\'             => true,
            \'menu_icon\'          => \'dashicons-format-audio\',
            \'can_export\'         => true,
            \'has_archive\'        => false,
            \'publicly_queryable\' => false,
            \'menu_position\' => \'20.1\',
        ];


$args = [
    \'label\'              => __(\'Master Artist Lookup\', SMF_CORE_NAME),
    \'labels\'             => [
        \'name\'          => __(\'Master Artist Lookup\', SMF_CORE_NAME),
        \'singular_name\' => __(\'Master Artist Lookup\'),
        \'add_new_item\'  => __(\'Add New Artist\', SMF_CORE_NAME),
        \'add_new\'       => __(\'Add New Artist\', SMF_CORE_NAME),
        \'new_item\'      => __(\'Add New Artist\', SMF_CORE_NAME),
        \'all_items\'     => __(\'All Artists\', SMF_CORE_NAME),
        \'edit_item\'     => __(\'Edit Artist\', SMF_CORE_NAME)
    ],
    \'supports\'           => [\'title\', \'thumbnail\'],
    \'hierarchical\'       => false,
    \'public\'             => true,
    \'menu_icon\'          => \'dashicons-format-audio\',
    \'can_export\'         => true,
    \'has_archive\'        => false,
    \'publicly_queryable\' => false,
    \'menu_position\' => \'20.2\',
        ];

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

有两种方法可以影响CPT在“管理”菜单中的显示位置:使用menu_position 以及控制注册CPT的时间。

根据我的经验,使用十进制数字并不可靠;使用整数,如21, 22, 等更有效。如果有太多的CPT,但没有足够的整数,另一个技巧是先注册所需的CPT,然后注册第二个CPT,然后注册第三个CPT。通过控制代码顺序,并保持menu_position 所有这些都是一样的,WP将按照您注册它们的顺序放置它们。

相关推荐