WordPress has the ability to split a post, or a multiple posts, into multiple pages. You can set how many data to list on each page. We can create a custom pagination links in wordpress without a plugins.

/*pagination*/
$sql = “SELECT * FROM $tbl_name”;
$total = $wpdb->get_var( “SELECT COUNT(1) FROM (${sql}) AS combined_table” );
$items_per_page = 3;
$page = isset( $_GET[‘kkpage’] ) ? abs( (int) $_GET[‘kkpage’] ) : 1;
$offset = ( $page * $items_per_page ) – $items_per_page;

$results = $wpdb->get_results($wpdb->prepare(“SELECT * FROM $tbl_name LIMIT $offset, ${items_per_page}”, OBJECT));

/*pagination*/

/*

Here goes the loop result

*/

/*

Display Pagination Links 

echo paginate_links( array(
‘base’ => add_query_arg( ‘kkpage’, ‘%#%’,’#all_image’ ),
‘format’ => ”,
‘prev_text’ => __(‘«’),
‘next_text’ => __(‘»’),
‘total’ => ceil($total / $items_per_page),
‘current’ => $page
));

*/

 

 

 

 

0 Comments

Leave a Comment