Wordpress:将管理员子菜单从帖子移动到父级别

时间:2017-10-12 08:11:19

标签: wordpress menu taxonomy submenu wp-admin

我想现在是否有任何方法可以从帖子中更改管理子菜单分类(作为类别和标签)的级别,使其成为父菜单(例如,页面,评论......)

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

You can change how high a menu will appear, but I'm quite sure that you can not change the level of a submenu, because for example the categories belong to the post type "post" as every taxonomy belongs to the post type on which they are defined...

You can set up otion pages, or custom post types, but the first one won't inculde taxonomies and the second one not directly, also just as a submenu...

Anyway, maybe you can do so with a java script hack changing the dom of the admin screen, but I wont recommend to do so! Is there a specific reason for that task?

答案 1 :(得分:0)

好的,我不知道我是否100%正确...你改变了默认“帖子”的名称和上诉!?

也许为此引入自定义帖子类型会更好,但这不会改变子菜单的问题,如前所述......

如果你的clinet想要那样,我们去,我测试了这个解决方案并且它工作正常,当然你可能需要做一些造型:

function load_custom_wp_admin_style() { ?>
<script>
    jQuery("#menu-posts ul li:nth-of-type(4)").prependTo("#adminmenu");
    jQuery("#menu-posts ul li:nth-of-type(4)").prependTo("#adminmenu");
</script>
<?php }
add_action( 'admin_footer', 'load_custom_wp_admin_style' );  

我将此代码添加到我的functions.php中,并将帖子类型“发布”的“类别”和“标签”移至“dashbord”之前的管理菜单顶部!

如果您希望在“仪表板”之后尝试使用:

function load_custom_wp_admin_style() { ?>
<script>
    jQuery("#menu-posts ul li:nth-of-type(4)").insertAfter("#menu-dashboard");
    jQuery("#menu-posts ul li:nth-of-type(4)").insertAfter("#menu-dashboard");
</script>
<?php }
add_action( 'admin_footer', 'load_custom_wp_admin_style' );

如果您没有使用帖子类型“帖子”,则必须更改选择器“#menu-posts”,只需在检查器中查找即可!

关于您的最后评论的编辑:

如果你想做一些样式,不要改变wordpress核心管理员,你将在每个wordpress更新上松开这些变化!!!

但你可以通过你的函数css插入样式,就像我们插入脚本一样,即通过css背景添加一个图标,如下所示:

function load_custom_wp_admin_style() { ?>
    <script>
        // I add an id to the element so it can be selected more easily for styling...      
        jQuery("#menu-posts ul li:nth-of-type(5)").attr('id', 'custom_tag_link');
        // Here I change the position as done before...
        jQuery("#menu-posts ul li:nth-of-type(5)").insertAfter("#menu-dashboard");

        jQuery("#menu-posts ul li:nth-of-type(4)").attr('id', 'custom_cat_link');
        jQuery("#menu-posts ul li:nth-of-type(4)").insertAfter("#menu-dashboard");
    </script>
    <style>
        /* Here comes the styling... */

        /* Do some margins/paddings and background-alignments... */
        #custom_cat_link, #custom_tag_link {
            background-size: auto 100%;
            background-repeat: no-repeat;
            padding-left: 25px !important;
            margin: 10px !important;
        }

        /* Set your Icons here... */
        #custom_cat_link {
            background-image: url('https://cdn0.iconfinder.com/data/icons/customicondesignoffice5/256/examples.png');   
        }   
        #custom_tag_link {
            background-image: url('https://cdn0.iconfinder.com/data/icons/customicondesignoffice5/256/examples.png');
        }       
    </style>
<?php }
add_action( 'admin_footer', 'load_custom_wp_admin_style' );

第二件事:重命名......如前所述,我不会更改帖子类型“帖子”,更好的做法是引入自定义帖子类型,你可以根据需要命名它们以及它们的分类法,但我想你现在不想改变它,所以我们再次使用JS的“不洁黑客”方式...完整代码:

function load_custom_wp_admin_style() { ?>
    <script>
        // I add an id to the element so it can be selected more easily for styling...      
        jQuery("#menu-posts ul li:nth-of-type(5)").attr('id', 'custom_tag_link');
        // Change the name of the <a>-element in the <li>-elem here...
        jQuery("#menu-posts ul li:nth-of-type(5) a").html('NEW TAG TITLE');
        // Here I change the position as done before...
        jQuery("#menu-posts ul li:nth-of-type(5)").insertAfter("#menu-dashboard");

        jQuery("#menu-posts ul li:nth-of-type(4)").attr('id', 'custom_cat_link');
        jQuery("#menu-posts ul li:nth-of-type(4) a").html('NEW CAT TITLE');
        jQuery("#menu-posts ul li:nth-of-type(4)").insertAfter("#menu-dashboard");
    </script>
    <style>
        /* Here comes the styling... */
        /* Do some margins/paddings and background-alignments... */
        #custom_cat_link, #custom_tag_link {
            background-size: auto 100%;
            background-repeat: no-repeat;
            padding-left: 25px !important;
            margin: 10px !important;
        }

        /* Set your Icon here... */
        #custom_cat_link {
            background-image: url('https://cdn0.iconfinder.com/data/icons/customicondesignoffice5/256/examples.png');   
        }   
        #custom_tag_link {
            background-image: url('https://cdn0.iconfinder.com/data/icons/customicondesignoffice5/256/examples.png');
        }       
    </style>
<?php }
add_action( 'admin_footer', 'load_custom_wp_admin_style' );

在这里你可以看到整个行动:

working example