Getting URL of next/previous links
-
Hi there,
Something that’s been asked a few times before but never truly resolved is how to get just the URL/permalink of the next and previous posts when on a current post. I need to feed these as variables into a Flash movie.
The next_post_link and previous_post_link tags unfortunately have the added contents of a href=”…” so I’d need to use PHP substring commands to strip those out, which I’d prefer not to have to do each time.
I could use the get_previous_post and get_next_post tags, for example:
<?php $prevPost = get_previous_post('','','','yes'); $prevURL = get_permalink($prevPost->ID); ?>
…but these tags are deprecated and it appears that there is still a problem if you want them to get posts only from the same category (at the moment they get posts from next and previous category too, even when in_same_cat is set to ‘yes’ like above).
There must be a way to get just the URLs, without needing a plugin or hacking WordPress back-end code.
Thanks for all the help.
Vaughan
- The topic ‘Getting URL of next/previous links’ is closed to new replies.