我重写了代码:
/*
Plugin Name: Admin Menu Post List
Plugin URI:
Description: Display a simple post list in admin menu for easy access
Version: 0.2
Author: Eliot Akira
Author URI:
License: GPL2
*/
/*
* Load CSS in header
*/
function custom_post_list_view_css() { ?>
<style>
.post_list_view_headline {
padding-left: 10px !important;
padding-right: 10px !important;
}
.post_list_view_post {
margin-left:12px;
}
.post_current a {
color:white !important;
}
</style>
<?php }
add_action( \'admin_head\', \'custom_post_list_view_css\' );
/*
* Admin Menu Post List
*/
add_action(\'admin_menu\', \'custom_post_list_view\');
function custom_post_list_view() {
/*** Get options ***/
$post_types = array( \'post\', \'page\' );
$current_post_ID = $_GET[\'post\']; /* Get current post ID on admin screen */
foreach ($post_types as $post_type) {
$custom_menu_slug = $post_type;
$output = \'\';
$args = array(
"post_type" => $post_type,
"parent" => "0",
"post_parent" => "0",
"numberposts" => "-1",
"orderby" => "menu_order",
"order" => "ASC",
"post_status" => "any",
"suppress_filters" => 0
);
$posts = get_posts($args);
if($posts) {
$output .= \'</a>\';
$output .= \'<div class="list_view_\' . $post_type . \'">\'
. \'<div class="post_list_view_headline">\' . \'<hr>\' . \'</div>\';
foreach ($posts as $post) {
$edit_link = get_edit_post_link($post->ID);
$title = get_the_title($post->ID);
$title = esc_html($title);
$output .= \'<div class="post_list_view_post\';
if($current_post_ID == ($post->ID)) {
$output .= \' post_current\';
}
$output .= \'">\'
. \'<a href="\'
. $edit_link . \'">\'
. $title . \'</a></div>\';
/*** Search for children? ***/
}
$output .= \'</div>\';
$output .= \'<a>\';
if($post_type == \'post\') {
add_posts_page( "Title", $output, "edit_posts", $custom_menu_slug, "custom_post_list_view_page");
} else {
if ($post_type == \'page\') {
add_pages_page( "Title", $output, "edit_pages", $custom_menu_slug, "custom_post_list_view_page");
} else {
if($post_type == \'attachment\') {
add_media_page("Title", $output, "edit_posts", $custom_menu_slug, "custom_post_list_view_page");
} else {
add_submenu_page((\'edit.php?post_type=\' . $post_type), "Title", $output, "edit_posts", (\'edit.php?post_type=\' . $post_type), "custom_post_list_view_page");
}
}
}
}
} // End foreach post type
}
function custom_post_list_view_page() { /* Empty */ }
现在它显示子菜单,当前类不会影响它。在输出子菜单的地方,我更改了
<ul>
和
<li>
到
<div>
. 我添加了一个检查,查看菜单项是否等于当前正在编辑的帖子,并在admin\\u标题中添加了一点CSS以突出显示该项。请参考上面的代码粘贴。
接下来,我将研究显示子页面。