3

I've been developing a plugin where I wanted to create a table, styled and working just like Wordpress's native Post/Page tables.

Following the guide below, I was able to create the table and load my database. The only thing I cannot figure out to do is how to make one of the row contents "clickable".

http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/

IE - making the "name" column clickable. I have the "edit, delete" buttons below the name, but that is not enough.

Any and all advice would be greatly appreciated. I looked at another plugin to see how they did this, and it looked like they broke the table apart and hardcoded the html for the table. I hope I don't have to do this.

EDIT:

clickable, linked, name

The name of the post, Hello world!, as you can see, is a link / clickable.

SOLUTION

to make this work, I had to remove my custom column functions, which included my row actions. Turns out, you can simply call the row actions div! Here is the function that helped me, thanks to the Milo.

function single_row_columns($item) {
       list($columns, $hidden) = $this->get_column_info();
            foreach ($columns as $column_name => $column_display_name) {
                   $class = "class='$column_name column-$column_name'";

                   $style = '';
                   if (in_array($column_name, $hidden))
                         $style = ' style="display:none;"';

                   $attributes = "$class$style";

                   if ('cb' == $column_name) {
                   echo  "<td $attributes>";
                   echo '<input type="checkbox" name="id[]" value="%s" />', $item['ID'];
                   echo "</td>";
                        }
               elseif ('galname' == $column_name) {
               echo "<td $attributes>";
               echo '<a href="#">', $item['galname'];
               echo "</a>";

                   echo "<div class='row-actions'><span class='edit'>";
           echo sprintf('<a href="?page=%s&action=%s&gid=%s">Edit</a>',$_REQUEST['page'],'edit',$item['id']);
                   echo "</span> | <span class='trash'>";
           echo sprintf('<a href="?page=%s&action=%s&gid=%s">Delete</a>',$_REQUEST['page'],'delete',$item['id']);
           echo "</span></div></td>";
                                                    }
            else {
                echo "<td $attributes>";
                echo $this->column_default( $item, $column_name );
                echo "</td>";
            } } } 

Thanks so much! Jacob

4
  • The tutorial you linked tells you how to do it under "Sorting".
    – Milo
    Commented Jan 26, 2013 at 18:55
  • Maybe you're seeing something I'm not, but I didn't find anything that said how to do that. I intend to make Hello World clickable, not the actual "title". My wording might have thrown that off. Commented Jan 26, 2013 at 19:06
  • oh, I understand. what's supposed to happen when you click it? wrap it in an anchor tag.
    – Milo
    Commented Jan 26, 2013 at 19:08
  • That's exactly what I want to do, but the current code I use to display my table doesn't include the functions required. Commented Jan 26, 2013 at 20:49

2 Answers 2

3

The WP_List_Table class ultimately uses the single_row_columns method to output each table cell. If we look at that method, we'll see this part:

...
elseif ( method_exists( $this, 'column_' . $column_name ) ) {
    echo "<td $attributes>";
    echo call_user_func( array( &$this, 'column_' . $column_name ), $item );
    echo "</td>";
}
...

Add a method to your class for the column you want to add additional functionality / formatting to and name it 'column_' . $column_name, then output any additional markup you need wrapping the item content.

4
  • I'm not sure how to incorporate this into my current display. I've added the "single_row_columns function. How do I call it? I'm going to edit my original post to include the code I use to display the results. Commented Jan 26, 2013 at 20:45
  • if your column is named title, add a function named column_title, the display method will call that function when outputting the text for the title column, passing $item as an argument to that function.
    – Milo
    Commented Jan 26, 2013 at 23:13
  • Thank you! I ended up removing my individual class calls, and making my own row actions. Commented Jan 27, 2013 at 9:46
  • I just tried out this method and it works very well. just concatenate the return value with your html (inside the column_Name function). for example: return "<a href='abc'>" . sprintf( $item['name'], $this->row_actions( $actions ) ) . "</a>";
    – fogx
    Commented Jul 2, 2019 at 8:56
0

If you mean the "Quick Edit" feature of the posts and comments tables: I'm working on a tutorial for this feature but it will take some time to find an easy understandable solution. As you might have guessed it's a mixture of PHP, jQuery and Ajax.

I've searched the Net for any hints on how to implement the feature but the only available example is the source of the WordPress core.

1
  • Nope, quick edit is not what I'm looking for. I'm editing my answer to include a picture of what I mean. Commented Jan 26, 2013 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.