What is the recommended way of creating a page with a table, in the style of the tables showing posts or users in the admin area?
I am expanding the Cache Images plugin, and it contains a table with domains and a number of images from that domain. So there is no equivalent existing table that I can build upon (in the first version of this question, I asked about a table with posts, but there I could (maybe) expand the existing post table).
Should I just base myself on the post overview page, and start with a <table class="widefat">
, or are there better functions that handle this now? Do you know a clean, empty example of a table with paging that I could base my work on?
This is what I generally use:
Hope that helps.
Use the Core API, not only its CSS
Normally you just use an instance of the
WP_List_Table
class.Guides:
Benefits?
YES!
You can add pagination, search boxes, actions and whatever magic you can imagine (and are able to code).
Use this example (written as a plugin) to create your admin tables:
http://wordpress.org/extend/plugins/custom-list-table-example/
It uses the built-in WP_List_Table class.
Also you can use this small plugin for view the possibilities of the backend in WP: https://github.com/bueltge/WordPress-Admin-Style
There are many good options here. But there isn’t a quick’n’dirty one:
Explanation
widefat
-class is used by thecommon.css
, loaded in the admin, to make it look like a WP-table.striped
-class makes it striped (what a surprise).fixed
-class adds the CSS:table-layout: fixed;
For those looking to implement
WP_List_Table
, please note that all guides I found are woefully out of date and will either have write redundant code or actually ask you to do things that no longer work.Here is a minimal example that works to some degree. It should be easy to understand without a “guide” and will get you started.
Includes:
Missing:
Then the admin page function (for
add_menu_page
/add_submenu_page
) may look like this:You might want to consider adding a filter to your custom post type list in the admin? The linked answer below shows how to do it with a taxonomy but you could easily use other criteria in your
restrict_manage_posts
hook:Let me know if you have more questions.