php - Adding Pagination to WordPress Page Templates -
i built wordpress theme existing theme (one engine theme). site launched , seems working except pagination. have tried many things failed work. template pages meant paginate @ point no 1 seem work. below looping code blog page template:
<?php $newsposts = get_posts(); foreach($newsposts $post) : setup_postdata($post); ?> //the html codes added here <?php endforeach; ?>
i want make post per page 4 , add default wordpress pagination function:
<?php posts_nav_link(); ?>
the page template here blog.php, can see page in action here: www.kayodeolusoji.net/blog appreciated!
try this:
i add 'paged' atrribute in $args wiht wp_query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $posts_per_page=4; $args = array( 'paged' => $paged, 'posts_per_page'=>$posts_per_page ); $newsposts = new wp_query($args); while($newsposts->have_posts()) :$newsposts->the_post(); echo $post->id.'<br />'; endwhile; wp_reset_query(); global $wp_query; $big = 999999999; echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $newsposts->max_num_pages ) );
Comments
Post a Comment