Support » Fixing WordPress » ‘Raw’ link to previous/next post

  • tyh

    (@tyh)


    Hi,

    Is there any way or any tags that can return the ‘raw’ link to previous/next posts? eg. http://mysite.com/post/

    Have tried various tags, but they all return .

    Am trying to put the previous/next post link in javascript.

Viewing 4 replies - 1 through 4 (of 4 total)
  • skippy

    (@skippy)

    Member

    get_previous_post() and get_next_post() are defined in wp-includes/template-functions-links.php.

    You could use these functions, and also review previous_post_link() and next_post_link() (both of which echo instead of return) for how to obtain the links you need.

    tyh

    (@tyh)

    Want to put the link in the code location.href=(link)

    Using get_previous_post() gives
    location.href=('')

    while using previous_post_link() gives
    location.href=('&laquo; <a href="http://mysite.com/link">Post title</a>')

    Have tried putting ‘echo get_previous_post()’ which gives location.href=('Object')

    Any ideas?

    n.b. In above post,
    Have tried various tags, but they all return .

    should be
    Have tried various tags, but they all return <a href="http://mysite.com/link"></a>.

    skippy

    (@skippy)

    Member

    get_previous_post() returns an actual post object. With this object, you could then feed the previous post’s ID to get_permalink().

    Also take a look at the arguments accepted by previous_post_link() and next_post_link() for ways to control and format the link.

    roterhund

    (@roterhund)

    Check out these wp-codex pages, you might find a solution for what you want to do:
    http://codex.wordpress.org/Template_Tags/previous_post
    http://codex.wordpress.org/Template_Tags/next_post

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘‘Raw’ link to previous/next post’ is closed to new replies.