此示例应用于post
岗位类型。这是利用WP_Posts_List_Table
类别和views-edit-{$post_type}
滤器这似乎不是最好的方法,但它很有效:
Make sure the class is loaded on your page:
if(!class_exists(\'WP_List_Table\')){
require_once( ABSPATH . \'wp-admin/includes/class-wp-list-table.php\' );
}
if(!class_exists(\'WP_Posts_List_Table\')){
require_once( ABSPATH . \'wp-admin/includes/class-wp-posts-list-table.php\' );
}
Extend the WP_Posts_List_Table
class to remove list table and define the custom content:
class wpse_CustomTable extends WP_Posts_List_Table
{
// remove search box
public function search_box( $text, $input_id ){ }
// Your custom list table is here
public function display() {
echo "Test";
}
}
Use it inside a filter hook:
// hook into `views-edit`
add_filter( \'views_edit-post\', "sstssfb_custom_list_table");
// Override the post table object
function sstssfb_custom_list_table() {
global $wp_list_table;
$mylisttable = new wpse_CustomTable();
$wp_list_table = $mylisttable ;
}
Result: