Skip to content

Instantly share code, notes, and snippets.

@tahirtaous
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tahirtaous/d67522c42f36a084843f to your computer and use it in GitHub Desktop.
Save tahirtaous/d67522c42f36a084843f to your computer and use it in GitHub Desktop.
WordPress Next & Prevous Page not Post with Bootstrap pager styling
<!-- add this code in page.php to display Next page and Previous page link below pages in WordPress
this will display next and previous page link not next previous post link
http://codex.wordpress.org/Next_and_Previous_Links#The_Next_and_Previous_Pages -->
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<ul class="pager">
<?php if (!empty($prevID)) { ?>
<li class="previous">
<a href="<?php echo get_permalink($prevID); ?>"
title="<?php echo get_the_title($prevID); ?>">Previous Page</a>
</li>
<?php }
if (!empty($nextID)) { ?>
<li class="next">
<a href="<?php echo get_permalink($nextID); ?>"
title="<?php echo get_the_title($nextID); ?>">Next Page</a>
</li>
<?php } ?>
</ul><!-- .navigation -->
@tahirtaous
Copy link
Author

If you want to display title of next and previous instead of PREVIOUS PAGE and NEXT PAGE use this code

<ul class="pager">
        <?php if (!empty($prevID)) { ?>
            <li class="previous">
            <a href="<?php echo get_permalink($prevID); ?>"
              title="<?php echo get_the_title($prevID); ?>"><?php echo get_the_title($prevID); ?></a>
            </li>
        <?php }
    if (!empty($nextID)) { ?>
            <li class="next">
                <a href="<?php echo get_permalink($nextID); ?>" 
             title="<?php echo get_the_title($nextID); ?>"><?php echo get_the_title($nextID); ?></a>
            </li>
        <?php } ?>
    </ul><!-- .navigation -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment