WordPress.org

Forums

Is it possible to use the_ID with offset (5 posts)

  1. Tunghsiao Liu (a.k.a. Sparanoid)
    Member
    Posted 4 years ago #

    Let's say there's an article with the_ID value 1, and I want to call the post_ID + 1 so I can get an achor link the navigate to next post, any good idea?

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    some of the below output links, others return a post object, which you can use to build your own links.

    in single posts:

    next_post_link()
    http://codex.wordpress.org/Function_Reference/next_post_link

    previous_post_link()
    http://codex.wordpress.org/Function_Reference/previous_post_link

    get_adjacent_post()
    http://codex.wordpress.org/Function_Reference/get_adjacent_post

    in the loop:

    get_next_post()
    http://codex.wordpress.org/Function_Reference/get_next_post

    get_previous_post()
    http://codex.wordpress.org/Function_Reference/get_previous_post

  3. Tunghsiao Liu (a.k.a. Sparanoid)
    Member
    Posted 4 years ago #

    Well, in the Parameters section I've seen it can just output the post title with %title, i wonder how to output only the post id just like the_ID does?

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    can you describe in more detail, where you want to get this next post id ( or link )?

    if you only want to output the post ID, then try:

    <?php $next_post = get_adjacent_post(false, '', false); echo $next_post->ID; ?>

    (next post is the one newer than the current)
    (similar for previous post)

  5. Tunghsiao Liu (a.k.a. Sparanoid)
    Member
    Posted 4 years ago #

    edit: Well, the problem solved, It's my mistake and your code is working now, thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by Tunghsiao Liu (a.k.a. Sparanoid)
  • Latest reply from Tunghsiao Liu (a.k.a. Sparanoid)
  • This topic is not resolved
  • WordPress version: 3.0.1

Tags