I want a pagination to my options page of wordpress plugin?

后端 未结 3 1378
轮回少年
轮回少年 2020-12-06 04:38

MY DEMO

I want a pagination according to the results coming from wordpress database...This is all done on my options page of wordpress plugin..

My code to re

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 05:41

    Take this https://stackoverflow.com/a/16358219/1596547 and adopt it to your needs like:

    $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
    
    $limit = 5; // number of rows in page
    $offset = ( $pagenum - 1 ) * $limit;
    $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM `wp_dive`" );
    $num_of_pages = ceil( $total / $limit );
    $result = $wpdb->get_results( "SELECT `id`,`name_cust`,`gender_cust`,`dob_cust` FROM `wp_dive` LIMIT $offset, $limit" );
    
    $data_html = '';
    
    foreach( $result as $results ) 
    
        {
        $id=$results->id;
        $name= $results->name_cust;
        $gender= $results->gender_cust;
        $dob= $results->dob_cust;
    ?>
    ";?>
    ". $id."";?>
    ". $name."";?>
    ".$gender."";?>
    ".  $dob ."";?>
    "?>
     add_query_arg( 'pagenum', '%#%' ),
        'format' => '',
        'prev_text' => __( '«', 'aag' ),
        'next_text' => __( '»', 'aag' ),
        'total' => $num_of_pages,
        'current' => $pagenum
    ) );
    
    if ( $page_links ) {
        echo '
    ' . $page_links . '
    '; }

提交回复
热议问题