Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add pagination in wordpress admin in my own customized plugin [closed]

Tags:

php

wordpress

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

like image 777
Yashrajsinh Jadeja Avatar asked Mar 16 '11 07:03

Yashrajsinh Jadeja


People also ask

How do I add pagination to WordPress admin?

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.

How do I get pagination on WordPress?

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.


1 Answers

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>';
}
like image 192
Hemi Avatar answered Oct 17 '22 05:10

Hemi