在预订插件中显示分页,并将表格打印为pdf

时间:2020-12-14 作者:Ayari

我想在我创建的插件页面中显示分页。。

我很感激如果有人能帮助我,我希望在后端分页(在管理中),而不是在前端,并打印为pdf的预订。这是我的函数如何添加分页并以pdf格式打印?

    function friday_reservations(){ 

<div class="wrap">
    <h1>Reservations</h1>
    <table class="wp-list-table widefat striped">
        <thead>
            <tr>
                <th class="manage-column">ID</th>
                <th class="manage-column">Gebet</th>
                <th class="manage-column">Genre</th>
                <th class="manage-column">Name</th>
                <th class="manage-column">Last Name</th>
                <th class="manage-column">E-mail</th>
                <th class="manage-column">Phone</th>
                <th class="manage-column">Number</th>
                <th class="manage-column">Delete</th>
            
            
            </tr>
        </thead>
        <tbody>
        <?php
            global $wpdb;
            $table = $wpdb->prefix . \'fridyreservation\';
            $reservations = $wpdb->get_results("SELECT * FROM $table", ARRAY_A);
           
            foreach($reservations as $reservation): ?>

                <tr>
                    <td><?php echo $reservation[\'id\']; ?></td>
                    <td><?php echo $reservation[\'predigt\']; ?></td>
                    <td><?php echo $reservation[\'genre\']; ?></td>
                    <td><?php echo $reservation[\'fname\']; ?></td>
                    <td><?php echo $reservation[\'lname\']; ?></td>
                    <td><?php echo $reservation[\'email\']; ?></td>
                    <td><?php echo $reservation[\'phone\']; ?></td>
                    <td><?php echo $reservation[\'pnumber\']; ?></td>
                    <td>
                        <a href="#" class="remove_reservation" data-reservation="<?php echo $reservation[\'id\']; ?>">Remove</a>
                    </td>
                
                </tr>


            <?php endforeach;
        ?>
        </tbody>
    </table>
</div>

1 个回复
SO网友:Ayari

您好,我通过以下方式找到解决方案:

https://stackoverflow.com/questions/5322266/add-pagination-in-wordpress-admin-in-my-own-customized-plugin

$pagenum = isset( $_GET[\'pagenum\'] ) ? absint( $_GET[\'pagenum\'] ) : 1;
$limit = 10; // number of rows in page
$offset = ( $pagenum - 1 ) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM {$wpdb->prefix}table_name" `);
$num_of_pages = ceil( $total / $limit );`
我将此更改为我的数据库:

$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}table_name LIMIT $offset, $limit" );
$page_links = paginate_links( array(
\'base\' => add_query_arg( \'pagenum\', \'%#%\' ),
\'format\' => \'\',
\'prev_text\' => __( \'&laquo;\', \'text-domain\' ),
\'next_text\' => __( \'&raquo;\', \'text-domain\' ),
\'total\' => $num_of_pages,
\'current\' => $pagenum
) );

if ( $page_links ) {
echo \'<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">\' . $page_links . \'</div></div>\';
}
仅此而已。刚才我必须找到如何删除所有保留?