Advertisement
Guest User

Untitled

a guest
Oct 15th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Admin Menu Post List
  4. Description: Display a simple post list in admin menu for easy access
  5. Version: 0.1
  6. */
  7.  
  8.  
  9. /*
  10.  * Load CSS in header
  11.  */
  12.  
  13. function custom_post_list_view_css() { ?>
  14.  
  15.     <style>
  16.         .post_list_view_headline {
  17.             padding-left: 10px !important;
  18.             padding-right: 10px !important;
  19.         }
  20.         .post_list_view_post a {
  21.             font-weight: normal !important;
  22.         }
  23.  
  24.     </style>
  25.  
  26. <?php }
  27. add_action( 'admin_head', 'custom_post_list_view_css' );
  28.  
  29.  
  30. /*
  31.  * Admin Menu Post List
  32.  */
  33.  
  34.  
  35. add_action('admin_menu', 'custom_post_list_view');
  36. function custom_post_list_view() {
  37.  
  38.     /*** Get options ***/
  39.  
  40.     $post_types = array( 'post', 'page' );
  41.  
  42.     foreach ($post_types as $post_type) {
  43.  
  44.         $custom_menu_slug = $post_type;
  45.  
  46.         $args = array(
  47.             "post_type" => $post_type,
  48.             "parent" => "0",
  49.             "post_parent" => "0",
  50.             "numberposts" => "-1",
  51.             "orderby" => "menu_order",
  52.             "order" => "ASC",
  53.             "post_status" => "any",
  54.             "suppress_filters" => 0
  55.         );
  56.  
  57.         $posts = get_posts($args);
  58.  
  59.         if($posts) {
  60.  
  61.             $output = '</a>';
  62.             $output .= '<ul class="list_view_' . $post_type . '">'
  63.                         . '<li class="post_list_view_headline">' . '<hr>' . '</li>';
  64.             foreach ($posts as $post) {
  65.                 $edit_link = get_edit_post_link($post->ID);
  66.                 $title = get_the_title($post->ID);
  67.                 $title = esc_html($title);
  68.                 $output .= '<li class="post_list_view_post"><a href="'
  69.                     . $edit_link    . '">'
  70.                     . $title . '</a></li>';
  71.  
  72.                 /*** Search for children? ***/
  73.  
  74.             }
  75.             $output .= '</ul>';
  76.             $output .= '<a>';
  77.  
  78.             if($post_type == 'post') {
  79.                 add_submenu_page('edit.php', "Title", $output, "edit_posts", 'slug-' . $custom_menu_slug, "custom_post_list_view_page");
  80.             } else {
  81.                 add_submenu_page(('edit.php?post_type=' . $post_type), "Title", $output, "edit_pages", 'slug-' . $custom_menu_slug, "custom_post_list_view_page");
  82.             }
  83.         }
  84.     } // End foreach post type
  85. }
  86.  
  87. function custom_post_list_view_page() { /* Empty */ }
  88.  
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement