• I’m trying to create a plugin that makes managing shortcodes much like managing posts, except (hopefully) much more intuitive. I have almost everything setup: admin page, general hooks (activation…), and a few other things. The issue I’m having, is that I can’t figure out how to display the entries from the database as a HTML table like with plugins. I’ve tried several guides, but can’t figure it out.

    I also need to design the page for editing or creating new shortcodes, but this, obviously, has to come first.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    After you extend WP_List_Table, the table is displayed by first calling prepare_items(), then display() class methods. But you probably figured out that much. Most of the work in extending the class is working up methods for each cell in the table, as well as code to deal with the various bulk actions, etc.

    Your best bet may be to pick an existing list table extension that’s close to what you want to do as a starting point, then begin editing the cell methods to fit your data schema. Basically using existing code as an example and template of what to do.

    The only reference I know of is oriented to modifying existing tables, not creating anew, but it has some good information that may be useful still. Just in case it helps, it’s here:
    https://glennmessersmith.com/pages/custom_columns.html

    If you get stuck, I can maybe help with a specific, detailed question, but as your question now stands, the answer is much too broad to get into within this forum format.

    Thread Starter octacian

    (@octacian)

    Thanks for the information. I am looking at the WordPress Contact Form 7 plugin while trying to figure this out. So far, I’ve gotten the class all set up, but I have no idea what to do from there.

    I assume I need to read the database table to an array, and then go from there, but if that’s the case I have no idea how to do it.

    I’ll take a look at that article tomorrow and hopefully I can figure something out from it. In the meantime, any help would be appreciated.

    The development repository can be found here, but it doesn’t have my latest changing while trying to actually get a table to display shortcodes. I uploaded this to ownCloud, and it can be found here, but I probably won’t update it unless I have another question related to an uncommited issue.

    Thanks again!

    Moderator bcworkz

    (@bcworkz)

    Yes, you would typically do a DB query in prepare_items(). It depends on what your table is going to display. If the data is not in the DB, then of course there’s no reason to query it. Maybe the data is on a remote server or for shortcodes, maybe all you need is the global $shortcode_tags.

    When display() is called, several sub-functions are called. You should trace through these just so you understand the process. Eventually a method to display a single row of data is called, which loops through all the columns, calling a specific callback for each column. These callbacks are part of what you need to provide in your class, since the content of each cell is dependent on the nature of your data and the column structure.

    Note that to have a sortable column, the column contents need to arrive by way of a DB query where the order can be flipped between ASC or DESC to get the desired column order. Data for non-sortable columns can come from anywhere.

    Of course there’s much more than this, like dealing with column headings, action links, view options, etc. Just too much to go into here. There’s several good examples for dealing with list tables in the core code, the terms list table for example. CF7 has a contact forms list table class which may serve as a good example since it is within a plugin. I realize reading through core code or other dev’s code can be mind numbing, but these working examples really are the best way to learn what needs to happen in your own code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a Table with WP_List_Table’ is closed to new replies.