Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Admin Menu Post List
- Description: Display a simple post list in admin menu for easy access
- Version: 0.1
- */
- /*
- * 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 a {
- font-weight: normal !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' );
- foreach ($post_types as $post_type) {
- $custom_menu_slug = $post_type;
- $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 .= '<ul class="list_view_' . $post_type . '">'
- . '<li class="post_list_view_headline">' . '<hr>' . '</li>';
- foreach ($posts as $post) {
- $edit_link = get_edit_post_link($post->ID);
- $title = get_the_title($post->ID);
- $title = esc_html($title);
- $output .= '<li class="post_list_view_post"><a href="'
- . $edit_link . '">'
- . $title . '</a></li>';
- /*** Search for children? ***/
- }
- $output .= '</ul>';
- $output .= '<a>';
- if($post_type == 'post') {
- add_submenu_page('edit.php', "Title", $output, "edit_posts", 'slug-' . $custom_menu_slug, "custom_post_list_view_page");
- } else {
- add_submenu_page(('edit.php?post_type=' . $post_type), "Title", $output, "edit_pages", 'slug-' . $custom_menu_slug, "custom_post_list_view_page");
- }
- }
- } // End foreach post type
- }
- function custom_post_list_view_page() { /* Empty */ }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement