' . __( 'Settings', 'admin_menu_post_list_settings_page' ) . ''; array_unshift( $links, $settings_link ); } return $links; } /* * Build post list */ function ampl_build_post_list_item($post_id, $post_type, $is_child, $child_query) { if( !isset($_GET['post']) ) $current_post_ID = -1; else $current_post_ID = $_GET['post']; /* Get current post ID on admin screen */ $edit_link = get_edit_post_link($post_id); $title = get_the_title($post_id); $title = esc_html($title); /* Limit title length */ if(strlen($title)>20) { if( function_exists( 'mb_substr' ) ) { $title = mb_substr($title, 0, 20) . '..'; } else { $title = substr($title, 0, 20) . '..'; } } $output = '
'; if ($is_child == 'child') { $output .= '— '; } /* Display post status */ switch(get_post_status($post_id)) { case 'draft': case 'pending': case 'future' : $output .= ''; break; } if($current_post_ID == ($post_id)) $output .= ''; /* Display post title */ $output .= $title; if($current_post_ID == ($post_id)) $output .= ''; switch(get_post_status($post_id)) { case 'draft': case 'pending': case 'future' : $output .= ''; break; } $output .= ''; /*** Search for children ***/ $children = get_posts(array( 'post_parent' => $post_id, 'post_type' => $post_type, "orderby" => $child_query['orderby'], "order" => $child_query['order'], 'post_status' => $child_query['post_status'], 'posts_per_page' => -1, )); if($children) { foreach($children as $child) { $output .= ampl_build_post_list_item($child->ID,$post_type,'child',$post_status); } } $output .= '
'; return $output; } add_action('admin_menu', 'custom_post_list_view', 11); function custom_post_list_view() { /** Get settings **/ $settings = get_option( 'ampl_settings' ); /*** Get all post types ***/ $post_types = get_post_types(); foreach ($post_types as $post_type) { /*** If enabled in settings ***/ if(!isset($settings['post_types'][$post_type])) $post_types_setting = 'off'; else $post_types_setting = $settings['post_types'][$post_type]; if($post_types_setting == 'on' ) { /* Get display options */ $max_limit = $settings['max_limit'][$post_type]; if($max_limit=='') $max_limit = 0; $post_orderby = $settings['orderby'][$post_type]; if($post_orderby=='') $post_orderby = 'date'; $post_order = $settings['order'][$post_type]; if($post_order=='') $post_order = 'ASC'; if( !isset($settings['exclude_status']) || !isset($settings['exclude_status'][$post_type])) $post_exclude = ''; else $post_exclude = $settings['exclude_status'][$post_type]; if($post_exclude=='') $post_exclude = 'off'; if($post_exclude=='on') { $post_exclude = 'publish'; } else { $post_exclude = 'any'; } $custom_menu_slug = $post_type; $output = ''; if ($max_limit==0) { $max_numberposts = 25; } else { $max_numberposts = $max_limit; } $args = array( "post_type" => $post_type, "parent" => "0", "post_parent" => "0", "numberposts" => $max_numberposts, "orderby" => $post_orderby, "order" => $post_order, "post_status" => $post_exclude, "suppress_filters" => 0 ); $child_query = array( "orderby" => $post_orderby, "order" => $post_order, "post_status" => $post_exclude, ); $posts = get_posts($args); if($posts) { $output .= ''; $output .= '
' . '
' . '
' . '
'; $count=0; foreach ($posts as $post) { if(($max_limit==0) || ($count<$max_limit)) $output .= ampl_build_post_list_item($post->ID, $post_type, 'parent', $child_query); $count++; } $output .= '
'; $output .= ''; 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", $custom_menu_slug, "custom_post_list_view_page"); } } } } } } // End foreach post type } function custom_post_list_view_page() { /* Empty */ } /* * Add admin menu style in header */ function custom_post_list_view_css() { ?> Select post types to enable', 'ampl_settings_field_input', 'ampl_settings_section_page_name', 'ampl_settings_section'); } function ampl_settings_section_page() { /* Empty */ } function ampl_settings_field_input() { $settings = get_option( 'ampl_settings'); ?> Post type Max items (0=all) Order by Order Show only published true)); $exclude_types = array('attachment'); foreach ($all_post_types as $key) { if(!in_array($key, $exclude_types)) { $post_types = isset( $settings['post_types'][ $key ] ) ? esc_attr( $settings['post_types'][ $key ] ) : ''; $post_type_object = get_post_type_object( $key ); $post_type_label = $post_type_object->labels->name; if(isset( $settings['max_limit'][ $key ] ) ) { $max_number = $settings['max_limit'][ $key ]; } else { $max_number = '0'; } if(isset( $settings['orderby'][ $key ] ) ) { $post_orderby = $settings['orderby'][ $key ]; } else { $post_orderby = 'date'; } if(isset( $settings['order'][ $key ] ) ) { $post_order = $settings['order'][ $key ]; } else { $post_order = 'DESC'; } if(isset( $settings['exclude_status'][ $key ] ) ) { $post_exclude = $settings['exclude_status'][ $key ]; } else { $post_exclude = 'off'; } ?> /> /> '; ?> /> '; ?> /> /> '; ?> /> /> true ); $post_types = get_post_types( $args ); unset( $post_types[ 'attachment' ] ); return apply_filters( 'ampl_get_post_types', $post_types ); } function ampl_settings_page() { ?>

Admin Menu Post List