-1

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

在此处输入图像描述

在此处输入图像描述

4

2 回答 2

1

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

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

如果您的客户希望这样,我们开始吧,我测试了这个解决方案,它工作正常,当然您可能需要做一些样式:

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中,这将帖子类型“posts”的“categories”和“tags”移动到“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' );

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

编辑关于您的最后评论:

如果您想做一些样式,请不要更改 wordpress 核心 admin-css,您将在每次 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 采用“不干净的 hack-a-like”方式......完整代码:

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' );

在这里,您可以看到整个过程:

工作示例

于 2017-10-12T12:41:13.097 回答
0

您可以更改菜单显示的高度,但我很确定您不能更改子菜单的级别,因为例如类别属于帖子类型“帖子”,因为每个分类都属于其上的帖子类型它们被定义...

您可以设置选项页面或自定义帖子类型,但第一个不包含分类法,第二个不直接,也只是作为子菜单...

无论如何,也许您可​​以通过更改管理屏幕的 dom 的 java 脚本 hack 来做到这一点,但我不建议这样做!该任务是否有特定原因?

于 2017-10-12T09:59:58.800 回答