📜  制作分页 wordpress 管理面板 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:29.340000             🧑  作者: Mango

代码示例1
// page parameter
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
// Find total number of records

$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 );

// Give Limit
$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}table_name LIMIT $offset, $limit" );


// add this code where you want to add pagintaion
$page_links = paginate_links( array(
    'base' => add_query_arg( 'pagenum', '%#%' ),
    'format' => '',
    'prev_text' => __( '«', 'text-domain' ),
    'next_text' => __( '»', 'text-domain' ),
    'total' => $num_of_pages,
    'current' => $pagenum
) );

if ( $page_links ) {
    echo '
' . $page_links . '
'; }