• I am creating a portfolio site and I want to be able to provide a “jump link” to the next post below the current one. I’m using full page screenshots for the portfolio, so the length of one “post” can be lengthy.

    So, basically I’m looking for a way to get the next post ID and insert that in the previous post as a #post-10 link. Is there a way to do that? If so, could someone either guide me to it or walk me through it?

    TIA!

    Oh, and I’m using 2.9.2 but it’s not in the drop-down.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not sure what you mean by ‘#post-10 link’. If you are using a loop with posts_per_page = 1 to show one post per page, then the standard previous/next_post_link() functions will get the links for you.

    Thread Starter popstalin

    (@popstalin)

    I’ll have maybe 5 posts on one page. There will be the title, plus date and tags and off the the right will be a jump link that says “next project”.

    Below the title and meta info, will be a large screenshot and then text to the right of it. The screenshot could be 1800 pixels long (depending on the length of the page). I want to be able for the viewer to click on “next project” and jump/scroll to the post below that (the previous post). On the next post, I’d like the same action, etc.

    Make sense?

    Thread Starter popstalin

    (@popstalin)

    So, I created a way to do this in case there isn’t an easy way to do it with WP functions, etc.

    I created a custom field for the previous posts’ id and then called the meta in my template. It’s not ideal but it works.

    <?php
     $prevPostID = get_post_meta ($post ->ID, 'previous_post_id', true);
     ?>
    
    <?php if ($prevPostID) { echo '<a href="' . $prevPostID.'">Next Project</a>';
        }
     ?>

    I think you can just add a few lines in your loop (your placement will vary depending on where you want the jump to appear):

    if (have_posts()) : $jumpcnt = 0; ?>
       <?php while (have_posts()) : the_post(); ?>
          <?php echo "<a name='jump$jumpcnt'></a>";
          ++$jumpcnt;
          echo "<a href='#jump$jumpcnt'>Next Project</a>";?>
          // Rest of the loop

    You might also want to put a jump back to the top after the loop:

    endwhile;
       echo "<a href='#jump0'>Back to Top</a>";?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Creating “jump link” to next post’ is closed to new replies.