Skip to main content
Edited answer as per user feedback
Source Link
Craig Pearson
  • 839
  • 1
  • 5
  • 19

This code should help you achieve what you want to, if you swap the code below

<?php wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
 'after' => '</div>', 'next_or_number' => 'next', 'previouspagelink' =>
 __('Previous'), 'nextpagelink'=> __('Next')  ) );?>

With this code

<?php 

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">', 
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '', 
'next_or_number' => 'next' ) ); 

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '', 
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) ); 

?>

This will show Next and Previous Links with the page count in between.

To get your next button to click through to the next post you can possibly further your code with something like this:

<?php
// If the current page equals the last page
if ($page == count($pages)): 
  // Prepare the next post
  // See: https://codex.wordpress.org/Function_Reference/get_next_post
  $next_post = get_next_post(); 
  // Then spit out the next link
  ?>
  <a href="<?php echo get_permalink( $next_post->ID ); ?>">Next</a>
<?php
// End the if statement
endif; ?>

This code should help you achieve what you want to, if you swap the code below

<?php wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
 'after' => '</div>', 'next_or_number' => 'next', 'previouspagelink' =>
 __('Previous'), 'nextpagelink'=> __('Next')  ) );?>

With this code

<?php 

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">', 
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '', 
'next_or_number' => 'next' ) ); 

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '', 
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) ); 

?>

This will show Next and Previous Links with the page count in between.

To get your next button to click through to the next post you can possibly further your code with something like this:

<?php
// If the current page equals the last page
if ($page == $pages): 
  // Prepare the next post
  // See: https://codex.wordpress.org/Function_Reference/get_next_post
  $next_post = get_next_post(); 
  // Then spit out the next link
  ?>
  <a href="<?php echo get_permalink( $next_post->ID ); ?>">Next</a>
<?php
// End the if statement
endif; ?>

This code should help you achieve what you want to, if you swap the code below

<?php wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
 'after' => '</div>', 'next_or_number' => 'next', 'previouspagelink' =>
 __('Previous'), 'nextpagelink'=> __('Next')  ) );?>

With this code

<?php 

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">', 
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '', 
'next_or_number' => 'next' ) ); 

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '', 
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) ); 

?>

This will show Next and Previous Links with the page count in between.

To get your next button to click through to the next post you can possibly further your code with something like this:

<?php
// If the current page equals the last page
if ($page == count($pages)): 
  // Prepare the next post
  // See: https://codex.wordpress.org/Function_Reference/get_next_post
  $next_post = get_next_post(); 
  // Then spit out the next link
  ?>
  <a href="<?php echo get_permalink( $next_post->ID ); ?>">Next</a>
<?php
// End the if statement
endif; ?>
Expanded and gave more detailed answer
Source Link
Craig Pearson
  • 839
  • 1
  • 5
  • 19

Hopefully this willThis code should help: you achieve what you want to, if you swap the code below

<?php wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
 'after' => '</div>', 'next_or_number' => 'next', 'previouspagelink' =>
 __('Previous'), 'nextpagelink'=> __('Next')  ) );?>

With this code

<?php 

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',  
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '',  
'next_or_number' => 'next' ) );  

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '',  
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) ); 

?>

This will show Next and Previous Links with the page count in between.

To get your next button to click through to the next post you can possibly further your code with something like this:

<?php
// If the current page equals the last page
if ($page == $pages): 
  // Prepare the next post
  // See: https://codex.wordpress.org/Function_Reference/get_next_post
  $next_post = get_next_post(); 
  // Then spit out the next link
  ?>
  <a href="<?php echo get_permalink( $next_post->ID ); ?>">Next</a>
<?php
// End the if statement
endif; ?>

Hopefully this will help:

global $page, $pages;

wp_link_pages( array( 'before' => '<div class="page-link-next-prev">', 'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '', 'next_or_number' => 'next' ) ); 

echo( $page.' of '.count($pages) );

wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '', 'nextpagelink' => 'Next', 'next_or_number' => 'next' ) ); 

This code should help you achieve what you want to, if you swap the code below

<?php wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
 'after' => '</div>', 'next_or_number' => 'next', 'previouspagelink' =>
 __('Previous'), 'nextpagelink'=> __('Next')  ) );?>

With this code

<?php 

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',  
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '',  
'next_or_number' => 'next' ) );  

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '',  
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) ); 

?>

This will show Next and Previous Links with the page count in between.

To get your next button to click through to the next post you can possibly further your code with something like this:

<?php
// If the current page equals the last page
if ($page == $pages): 
  // Prepare the next post
  // See: https://codex.wordpress.org/Function_Reference/get_next_post
  $next_post = get_next_post(); 
  // Then spit out the next link
  ?>
  <a href="<?php echo get_permalink( $next_post->ID ); ?>">Next</a>
<?php
// End the if statement
endif; ?>
Source Link
Craig Pearson
  • 839
  • 1
  • 5
  • 19

Hopefully this will help:

global $page, $pages;

wp_link_pages( array( 'before' => '<div class="page-link-next-prev">', 'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '', 'next_or_number' => 'next' ) ); 

echo( $page.' of '.count($pages) );

wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '', 'nextpagelink' => 'Next', 'next_or_number' => 'next' ) );