I've been reviewing any plugin that may help in this but I got nothing. For a web using pages instead of posts, I may need to show in each page a menu consisting of 20 previous pages, or maybe 10 previous pages and 10 next pages links, excluding those situations where there are no previous or next pages.

I can find something like this for posts in plugins if I'm not wrong but not for pages. Asking in the WordPress forums got no answer either. Maybe it is more complicated than I though initially. If there is any code I may paste in a widget (there are php widgets to show code) that would be enough, as I may change parameters to adjust it.

Update: Im not comfy writing php. I can read though it and maybe change a value, if it is properly commented, thats all. Im asking in case there is such an option hidden in some plugin from wordpress.org i may have overlooked, or if it is simple enough to achieve pasting a few lines of php in a widget like: php code widget (this is the name of a plugin).

As I explain all i pretend is to show the previous 10 and next 10 pages linked titles from the current page browsed by id or date.

Lets put it this way. It would be a glorified navigation code, like that of wp page navi, although instead of showing below page content showing only a link for the previous page called previous and a link for the next page called next, it would show linked titles for the previous 10 pages and for the next 10, preferably in the sidebar, as i could paste the phpo code inside the php code widget anyway.

  • This is not an especially difficult problem if you are familiar with the WP functions and classes and can write a little PHP. What is your comfort level with editing PHP files if code were provided to you?
    – jdm2112
    Oct 29, 2015 at 13:39

1 Answer 1


Here is a simple widget to get you started. You should be able to tweak it to get the effects you want.

class recent_pages extends WP_Widget {

  public function __construct() {
    // widget actual processes  
        'recent_pages', // Base ID
        'recent pages', // Name
        array( 'description' => __( 'Show the recent pages', 'foo'))
        // Args

  public function widget( $args, $instance ) {

    global $post;

    echo $args['before_widget'];

    if (!empty($instance['title'])) {
      $title = $instance['title'];
      echo $args['before_title'].$title.$args['after_title'];

    echo '<ul class="recent_pages">';   
    $pargs = array(
      'post_type' => 'page',
      'posts_per_page' => 10,
      'date_query' => array(
          'after' => $post->post_date
       'order' => 'ASC',
    $pages = new WP_Query($pargs);
    if ($pages->have_posts()) {
      while($pages->have_posts()) {
        echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>    <br>';
    echo '</ul>';
    echo $args['after_widget'];

     register_widget( 'recent_pages' );

It works mostly by using the date_query argument to WP_Query. Check the Codex for details of how that operates.

  • This looks mostly as a plugin called recent posts widget. The issue is that im not looking to show the last 10 post published, i can already do that with that plugin., Im looking to show the 10 previous and 10 next pages from whichever one you are currently browsing. Oct 31, 2015 at 14:29
  • Then you missed the date_query. It is a small thing, but an important one. Please take a better look at the code. You will need to do something similar but in reverse to get posts in the opposite direction.
    – s_ha_dum
    Oct 31, 2015 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.