Target the next ID inside the Loop (WP)

Is it possible to target the next section inside the loop? so that it will scroll down to the next section area.

Here is my code:

Read More
<section id ="<?php echo $postid; ?>" class="subpage-wrapper fullscreen background parallax" style="background-image: url('<?php echo $image[0]; ?>')" data-img-width="1400" data-img-height="717" data-diff="100" data-oriz-pos="100%">

<a href="#<?php echo $postid; ?>" class="btn-scroll" data-scroll></a>
</section>

Remember that this is inside the WP_Query Loop

Thanks!

Related posts

2 comments

  1. I’m not keeping any selections within your displaying of posts in mind, but I figure you can get ’round by using get_next_post(). Something like:

    global $post;
    $post = get_post($post_id);
    
    $next = get_next_post();
    $next_id = $next->id;
    
  2. What about using your own counter?

    $nextAnchorId = 0;
    while ( have_posts() ) { //the loop
        $nextAnchorId++; //make this actually be a reference to the *next* post
        the_post();
    
        if ($nextAnchorId < $post_count) //don't link to the next post if it's the last one
        {
            echo "<a href='#post-$nextAnchorId'>next post</a>";
        }
    }
    

Comments are closed.