<?php // WordPress $items_per_page = 10; $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1; $offset = ( $page * $items_per_page ) - $items_per_page; $query = 'SELECT * FROM '. $table_name; $total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table"; $total = $wpdb->get_var( $total_query ); $results = $wpdb->get_results( $query.' ORDER BY id DESC LIMIT '. $offset.', '. $items_per_page, OBJECT ); echo paginate_links( array( 'base' => add_query_arg( 'cpage', '%#%' ), 'format' => '', 'prev_text' => __('« Prev'), 'next_text' => __('Next »'), 'total' => ceil($total / $items_per_page), 'current' => $page ));Related Keywords: Developer, How-to, Solved, PHP Pagination, Reference
喜歡這篇文章嗎?
(暫時未有評分)
Loading...
(暫時未有評分)
Loading...