Empty Minimal WP_List_Table Examples

# function WP_List_Table::prepare_items() must be overridden in a subclass.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/c19c5b4c-8cd8-cab8-a1fe-16eeec60dabd.png)

```php
<?php

/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/

if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

class My_List_Table extends WP_List_Table
{
}

function my_render_list_page()
{
    $myListTable = new My_List_Table();
    $myListTable->prepare_items();
    $myListTable->display();
}

function my_add_menu_items()
{
    add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');

```

# function WP_List_Table::get_columns() must be overridden in a subclass.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/20022e3f-6931-1846-8338-354d99c85d2f.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/40d28a87-a67b-21d3-3d54-ad5be30402dd.png)

```php
<?php

/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/

if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

class My_List_Table extends WP_List_Table
{
    public function prepare_items() {
        
    }
}

function my_render_list_page()
{
    $myListTable = new My_List_Table();
    $myListTable->prepare_items();
    $myListTable->display();
}

function my_add_menu_items()
{
    add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');

```

# No items found.

`prepare_items()`を呼び出さない場合

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/8a5db24c-e01d-65e2-34dc-a75ff6ef5cd3.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/5509237c-fb5e-fda7-547d-e387fb052a05.png)


```php
<?php

/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/

if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

class My_List_Table extends WP_List_Table
{
    public function get_columns()
    {

    }
}

function my_render_list_page()
{
    $myListTable = new My_List_Table();
    $myListTable->display();
}

function my_add_menu_items()
{
    add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');

```

# No items found.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/3556eeec-522e-e2bb-2651-b7ab2bde7120.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/40acb444-6fca-55fc-4d3c-3188f0167ac1.png)

```php
<?php

/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/

if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

class My_List_Table extends WP_List_Table
{
    public function prepare_items() {

    }

    public function get_columns() {
        
    }
}

function my_render_list_page()
{
    $myListTable = new My_List_Table();
    $myListTable->prepare_items();
    $myListTable->display();
}

function my_add_menu_items()
{
    add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');

```

# 完成

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/a5156921-9df0-1ace-43e0-e5ca099189d0.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/435735/3cd8faa6-f75f-9d91-0594-98582c9af196.png)

```php
<?php

/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/

if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

class My_List_Table extends WP_List_Table
{
    public function prepare_items()
    {
        $this->items = [
            ['name' => 'りんご', 'color' => '赤', 'price' => 100],
            ['name' => 'バナナ', 'color' => '黄', 'price' =>  60],
            ['name' => 'メロン', 'color' => '緑', 'price' => 300],
        ];
        $this->_column_headers = [$this->get_columns()];
    }

    public function get_columns()
    {
        return [
            'name' => '名前',
            'color' => '色',
            'price' => '値段'
        ];
    }

    public function column_default($item, $column_name)
    {
        return $item[$column_name];
    }
}

function my_render_list_page()
{
    $myListTable = new My_List_Table();
    $myListTable->prepare_items();
    $myListTable->display();
}

function my_add_menu_items()
{
    add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');

```