Really struggling to add pagination to my wordpress blog posts.
I've seen a lot of tutorials but they all seem to do the problem that I'm having now.
If I add the function to the function.php file and then call it in my post I cant get the pagination to output onto the page.
The blogs allowed at the moment are 2 per page for testing purposes.
Function:
function twentyeleven_content_nav( $nav_id ) {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="<?php echo $nav_id; ?>">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
</nav><!-- #nav-above -->
<?php endif;
}
Post loop php:
<?php
$custom_posts = new WP_Query( array(
'order_by' => 'date'
));
if ( $custom_posts->have_posts() ) :
while ( $custom_posts->have_posts() ) : $custom_posts->the_post(); $loopcounter++;
if ($loopcounter == 1) {
get_template_part( 'content', 'first-post' );
} else {
get_template_part( 'content', get_post_format() );
}
endwhile;
twentyeleven_content_nav( nav );
else :
get_template_part( 'content', 'none' );
endif;
?>
Let me know if you need any further information
PS want this to be custom NO PLUGINS thanks
****** UPDATE ******
<?php
$custom_posts = new WP_Query( array(
'order_by' => 'date'
));
if ( $custom_posts->have_posts() ) :
while ( $custom_posts->have_posts() ) : $custom_posts->the_post(); $loopcounter++;
if ($loopcounter == 1) {
get_template_part( 'content', 'first-post' );
} else {
get_template_part( 'content', get_post_format() );
}
endwhile;
if(function_exists('pagenavi')) { pagenavi(); };
else :
get_template_part( 'content', 'none' );
endif;
?>