Ad 468 X 60

Monday, 26 May 2014

Widgets

Add pagination in my own plugin in wordpress?

Dear Users,
In this post i will describe how to add pagination in my own plugin with step by step.
as we know wordpress provide us a very huge library of code for every thing that you need in a website. it is very simple task to add pagination in custom plugins. now here i just explain some step of code that will easily add pagination upper and lower section of table .
Here are some  easy step that will help to show pagination in your plugin .
1)
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;


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

3)

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


4)
$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>'; }


SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati

1 comment: