我想用动作渲染列。
当鼠标悬停在行上时,Edit | Delete
链接显示。
功能出现问题column_name($item)
.
我不知道为什么不运行此函数。
我试图添加wp_die()
但没有任何更改。
我编写了类扩展WP_List_Table
:
class Custom_Table_Example_List_Table extends WP_List_Table
{
function __construct()
{
global $status, $page;
parent::__construct(array(
\'singular\' => \'dathangnhanh\',
\'plural\' => \'dathangnhanhs\',
));
}
/**
* [OPTIONAL] this is example, how to render column with actions,
* when you hover row "Edit | Delete" links showed
*
* @param $item - row (key, value array)
* @return HTML
*/
function column_name($item)
{
// links going to /admin.php?page=[your_plugin_page][&other_params]
// notice how we used $_REQUEST[\'page\'], so action will be done on curren page
// also notice how we use $this->_args[\'singular\'] so in this example it will
// be something like &dathangnhanh=2
$actions = array(
\'edit\' => sprintf(\'<a href="?page=persons_form&id=%s">%s</a>\', $item[\'id\'], __(\'Edit\', \'cltd_example\')),
\'delete\' => sprintf(\'<a href="?page=%s&action=delete&id=%s">%s</a>\', $_REQUEST[\'page\'], $item[\'id\'], __(\'Delete\', \'cltd_example\')),
);
return sprintf(\'%s %s\',
$item[\'madonhang\'],
$this->row_actions($actions)
);
}
/**
* [REQUIRED] This method return columns to display in table
* you can skip columns that you do not want to show
* like content, or description
*
* @return array
*/
function get_columns()
{
$columns = array(
\'cb\' => \'<input type="checkbox" />\', //Render a checkbox instead of text
\'id\' => __(\'STT\', \'cltd_example\'),
\'madonhang\' => __(\'Mã Đơn Hàng\', \'cltd_example\'),
\'hoten\' => __(\'Họ Tên\', \'cltd_example\'),
\'sdt\' => __(\'Số Điện Thoại\', \'cltd_example\'),
\'email\' => __(\'Email\', \'cltd_example\'),
\'tensp\' => __(\'Tên Sản Phẩm\', \'cltd_example\'),
\'diachinhan\' => __(\'Địa Chỉ Nhận\', \'cltd_example\'),
\'soluong\' => __(\'Số Lượng\', \'cltd_example\'),
\'thanhtien\' => __(\'Thành Tiền\', \'cltd_example\'),
);
return $columns;
}
}