如何添加管理栏和管理菜单或子菜单通知气泡?

时间:2012-11-07 作者:Michael Ecklund

就操作admin bar 走了?我想添加一个新的管理栏节点,并用CSS为图标设置背景图像。然后在节点中,只输出计数。

enter image description here

我不知道如何在管理菜单或管理子菜单上添加气泡通知。有什么建议吗?

2 个回复
最合适的回答,由SO网友:Michael Ecklund 整理而成

您只需使用CSS创建气泡(圆),并在其顶部创建文本站点。

CSS示例

span.mbe-update-bubble{
    position: absolute !important;
    top: 6px !important;
    left: 6px !important;
    -webkit-border-radius: 10px !important;
    -khtml-border-radius: 10px !important;
    -moz-border-radius: 10px !important;
    border-radius: 10px !important;
    background: #ccc !important;
    color: #464646 !important;
    width: 10px !important;
    height: 10px !important;
    padding: 3px !important;
    font-size: 11px !important;
    line-height: 10px !important;
    display: inline-block !important;
    text-align: center !important;
    text-shadow: none !important;
    font-weight: bold !important;
}
span.mbe-ab-text{
    position: relative !important;
    margin: 0px -6px !important;
    font-weight: normal !important;
}
span.mbe-ab-text-active{
    position: relative !important;
    margin-left: 14px !important;
    color: #91b1c6 !important;
    font-weight: bold !important;
    text-shadow: 0px 0px 1px #000 !important;
}
添加挂起的帖子功能:

function admin_tool_bar($wp_admin_bar){
    global $wp_admin_bar;
    $post_type = \'testimonial\';
    $count = wp_count_posts($post_type);
    $args = array(
        \'id\' => \'mbe_testimonials_pending\',
        \'href\' => admin_url(\'/edit.php?post_status=pending&post_type=\'.$post_type, \'http\'),
        \'parent\' => \'top-secondary\'
    );
    if($count->pending == 1){
        $title = \' Testimonial Awaiting Moderation\';
    } else{
        $title = \' Testimonials Awaiting Moderation\';
    }
    $args[\'meta\'][\'title\'] = $title;
    if($count->pending == 0){
        $display = \'<span class="mbe-ab-text">\'.$count->pending.\' \'.$title.\'</span>\';
    } else{
        $display = \'<span class="mbe-update-bubble">\'.$count->pending.\'</span><span class="mbe-ab-text-active">\'.$title.\'</span>\';
    }
    $args[\'title\'] = $display;
    $wp_admin_bar->add_node($args);
}
为了添加管理栏项,启动挂钩:add_action(\'wp_before_admin_bar_render\', \'admin_tool_bar\', 999);

示例屏幕截图:

enter image description here

SO网友:revive

我没有关于管理栏气泡的答案,但下面是如何将其添加到新的管理菜单项中,如下所示:

(注意:这里我得到的是一组重力表单字段的计数,但您可以更改获取计数的位置..显示仍然相同)

function register_my_custom_menu_page() {
    $search_criteria = array(
        \'status\'     => \'active\', //Active forms 
        \'field_filters\' => array( //which fields to search
            array(
                \'key\' => \'is_read\', \'value\' => false, // let\'s just get the count for entries that we haven\'t read yet.
            )
          )
        );

    // Add the form IDs to the array below, the parent menu will show ALL unread entries for these forms
    $notification_count = GFAPI::count_entries( array(1,4,5,6,11,13), $search_criteria );
    
    add_menu_page(
        \'Full Quote Form submissions\', // Page Title
        // here we\'re going to use the var $notification_count to get ALL the form IDS and their counts... just for the parent menu item
        $notification_count ? sprintf( \'Quotes <span class="awaiting-mod">%d</span>\', $notification_count ) : \'View Quotes\',
        \'manage_options\', // Capabilities 
        \'admin.php?page=gf_entries&id=13\', // menu slug
        \'\', // callback function
        \'dashicons-format-aside\', // icon URL
        6 // position
    );
}
add_action( \'admin_menu\', \'register_my_custom_menu_page\' );

结束

相关推荐

是否将admin startPage更改为Pages-Page?

当您登录到管理员时,默认情况下会看到欢迎页面。我的一个客户请求默认情况下查看“页面”页面,他在其他地方看到了它。这是否可能,如果可能,如何实现?尝试搜索,但未找到相关内容,在设置中也未找到。