• Hello, I was wondering if there was some way to accomplish this, on index.php and the archives:

    If this is the first page:

    << Previous Posts

    If it’s any other page, besides the last one:

    << Previous Posts | Next Posts >>

    Last page:

    Next Posts >>

    Basically, have a vertical pipe in between the previous and next post links only when the two links are shown, ie not the first and last pages.

    Any help is greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I suppose you could use one of the functions listed here (https://codex.www.ads-software.com/Function_Reference) but determining which page is first or next would depend on how you sorted the results.

    By default I assume the posts are returned by PKID and can possibly be ordered by DATE or TITLE, etc.

    Look at the function singature in the wp-includes/post.php to see what functions take what arguments.

    This is how I would do it with my limited knowledge of WordPress:

    $cur = get_the_ID(); // Get ID of currently active page?
    
    // You could probably use another funciton to actually filter
    // so that you only look for pages under category A for instance
    $arr = get_all_page_ids(); // Get array of ALL pages
    $arr = array_values($arr); // Only interested in PKID's
    
    $prev = prev($arr[$cur]);
    $next = next($arr[$cur]);
    
    $pipe = false; // TRUE means we vertical pipe separator is required
    
    if ($prev !== false) {
      $pipe = true;
      echo '<a href="">Previous Posts</a>';
    }
    
    if ($next !== false) {
      if($pipe === true){
        echo '&nbsp;|&nbsp;';
      }
      echo '<a href="">Next Posts</a>';
    }

    Totally un-tested but it should give you an idea as to where to start???

    Hope it helps ??

    <?php if($paged && ($paged != 1) && ($paged != $wp_query->max_num_pages)) echo " | "; ?>

    Thread Starter dylan-hilton

    (@dylan-hilton)

    Thanks so much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Previous_Post_Link – Extra character?’ is closed to new replies.