Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
- $args = array(
- 'posts_per_page' => 5,
- 'paged' => $paged
- );
- $custom_query = new WP_Query( $args );
- // Output custom query loop
- if ( $custom_query->have_posts() ) :
- while ( $custom_query->have_posts() ) :
- $custom_query->the_post();
- // Loop output goes here
- endwhile;
- endif;
- // Reset postdata
- wp_reset_postdata();
- //wp_query object is not available in wp-admin. so we need to design custom pagination
- // Pagination
- $max_pages = $custom_query->max_num_pages;
- $nextpage = $paged + 1;
- $previouspage = $paged - 1;
- if ($max_pages > $paged) {
- echo '<a href="admin.php?page=plugin_page.php&paged='. $nextpage .'">Load More Posts</a>';
- }
- if ( $paged > 1 ) {
- echo '<a href="admin.php?page=plugin_page.php&&paged='. $previouspage .'">Load Previous Posts</a>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement