In the WordPress dashboard, the tables that displays the posts, pages and user data are all created internally by WordPress using the WP_List_Table PHP class.
在WordPress仪表板中,用于显示帖子,页面和用户数据的表都是由WordPress使用WP_List_Table PHP类内部创建的。
Below are a couple of screenshots of the post and user admin pages:
以下是帖子和用户管理页面的几个屏幕截图:


As a plugin developer, the need to build a custom table that will contain a given data might arise. Rather than code your own table design, it’s best you use that of WordPress in order for your plugin settings page to conform to WordPress UI.
作为插件开发人员,可能需要构建一个包含给定数据的自定义表。 最好不要使用自己的表设计,而最好使用WordPress的表设计,以使插件设置页面符合WordPress UI。
While you might be tempted to copy the HTML and CSS table design by viewing the source code of WordPress, you shouldn’t because the WP_List_Table
class is there to help.
尽管您可能会通过查看WordPress的源代码来尝试复制HTML和CSS表格设计,但您不应该这样做,因为WP_List_Table
类可以提供帮助。
My acquaintance with WP_List_Table
stemmed from my experience building the ProfilePress plugin. I actually used it to display the list of created user account forms in table form.
我对WP_List_Table
了解源于我构建ProfilePress插件的经验。 我实际上使用它来以表格形式显示创建的用户帐户形式的列表。

You’ve probably used plugins that use WP_List_Table, for example, the popular Contact Form 7 plugin uses the class to display the list of created contact forms.
您可能曾经使用过使用WP_List_Table的插件,例如,流行的Contact Form 7插件使用该类显示已创建的联系表的列表。
熟悉WP_List_Table (Getting Familiar with WP_List_Table)
We’ll build a plugin to demonstrate how to display the dummy customer database below in a table format using WP_List_Table
class.
我们将构建一个插件来演示如何使用WP_List_Table
类以表格式显示下面的虚拟客户数据库。

The plugin is comprised of two classes: a child class of WP_List_Table
and the plugin settings class.
该插件包括两个类: WP_List_Table
的子类和插件设置类。
扩展WP_List_Table (Extending WP_List_Table)
To build a WordPress UI table, the WP_List_Table
will have to be extended with a couple of its methods overridden by a child class.
要构建WordPress UI表,必须使用子类覆盖的WP_List_Table
扩展其几个方法。
Firstly, we include the class in the plugin.
首先,我们在插件中包含该类。
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
We then create a child class that extends WP_List_Table
. The child class will be called Customers_List
since we are dealing with a database of customers.
然后,我们创建一个扩展WP_List_Table
的子类。