$args = array( 'category_name' => 'news', 'posts_per_page' => 10 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // output post content here } wp_reset_postdata(); }
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'page', 'posts_per_page' => 5, 'paged' => $paged ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // output page content here } global $wp_query; $big = 999999999; $total_pages = $query->max_num_pages; echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $total_pages ) ); wp_reset_postdata(); }Package Library: WordPress Core