i want to display pagination in one of my page of plugin,created by me.. i tried lots of examples but no one is working..
i'll be vary thankful if anyone can give answer...
note: i want pagination in back end(in admin) not in front end
To configure the plugin, go to the new Pagination tab in your dashboard. The plugin's default settings will automatically hide your theme's existing pagination and replace it with the custom pagination from the plugin. All you need to do is configure the settings for the style and behavior of your new pagination.
WordPress provides several functions for automatically displaying a numerical pagination list. If you want more robust pagination options, you can use the_posts_pagination() for WordPress 4.1 and higher. This will output a set of page numbers with links to previous and next pages of posts.
Easy Steps :
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
Find total numbers 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 pagination:
$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 '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With