WordPress.org

Ready to get started?Download WordPress

Forums

Previous_Post_Link - Extra character? (4 posts)

  1. Dylan Hilton
    Member
    Posted 5 years ago #

    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.

  2. Anonymous
    Unregistered
    Posted 5 years ago #

    I suppose you could use one of the functions listed here (http://codex.wordpress.org/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 :)

  3. Murmatron 2
    Member
    Posted 5 years ago #

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

  4. Dylan Hilton
    Member
    Posted 5 years ago #

    Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic