I have made a template for my blog page to call in all recent blogs showing 2 blogs per page. I have added a pagination function on the loop but it is just calling the same page over and over and showing the same 2 blog excerpts, even when the url reads /blog/page/2. However when I am clicking the pagination link in blogs that open in the categories archive the pagination works and shows the next 2 blogs? Please help
Template for blog page:
<?php
/*
* Template Name: Blog Homepage
*/
get_header()?>
<main role="main">
<section>
<div id="bp-column-L">
<h1>Our Most Recent Blogs</h1>
<?php query_posts("posts_per_page=2"); ?>
<?php get_template_part('loop'); ?>
</div>
<?php get_sidebar(); ?>
</section>
</main>
</div>
<?php get_footer()?>
The php page for the loop being called:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!--article-->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
</a>
<?php endif; ?>
<!-- /post thumbnail -->
<!-- post title -->
<h2>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<!-- /post title -->
<!-- post details -->
<span class="date"><?php the_time('F j, Y'); ?> <?php the_time('g:i a'); ?></span>
<span class="author"><?php _e( 'Published by', 'html5blank' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span>
<!-- /post details -->
<?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>
<?php edit_post_link(); ?>
</article>
<!-- /article -->
<?php endwhile; ?>
<?php get_template_part('pagination'); ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
And the function being called is:
function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}