/*
Template: jin
Theme Name: jin-child
Author: CrossPiece
Version: 1.00
*/

function card_list_table() {

    ob_start();

    $args = array(
        'post_type' => 'card',
        'posts_per_page' => -1
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {

        echo '<table border="1" style="width:100%; text-align:center;">';
        echo '<tr>
                <th>画像</th>
                <th>名前</th>
                <th>色</th>
                <th>体力</th>
                <th>攻撃力</th>
                <th>コスト</th>
              </tr>';

        while ($query->have_posts()) {
            $query->the_post();

            echo '<tr>';
            echo '<td>' . get_the_post_thumbnail(get_the_ID(), 'thumbnail') . '</td>';
            echo '<td><a href="' . get_permalink() . '">' . get_the_title() . '</a></td>';
            echo '<td>' . get_field('card_color') . '</td>';
            echo '<td>' . get_field('card_hp') . '</td>';
            echo '<td>' . get_field('card_attack') . '</td>';
            echo '<td>' . get_field('card_cost') . '</td>';
            echo '</tr>';
        }

        echo '</table>';

    } else {
        echo 'カードがまだ登録されていません。';
    }

    wp_reset_postdata();

    return ob_get_clean();
}

add_shortcode('card_list', 'card_list_table');
