Believe this would work in the loop of your single.php
<?php
$adjacent_post = get_adjacent_post(false,'',false) ;
echo $adjacent_post->ID;
?>
Great, thanx!
and this code to previous post id
$adjacent_post = get_adjacent_post(true,'',true) ;
$adjacent_post = get_adjacent_post(true,'',true) ;
That would be for next post in category
More illustration:
$in_same_cat = false;
$excluded_categories = '';
$previous = true;
$previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous)
$in_same_cat = false;
$excluded_categories = '';
$previous = false;
$next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous)
This is exactly what I’m looking for as well. However, I tried the exact code within my wordpress loop, and it didn’t return anything for me?
I’m running version 2.9.2
I also can’t find any documentation about the get_adjacent_post tag. Is this tag still supported in the current version of wordpress?
I realized that this only returns a result on the single permalink page. So I’m wondering if there is a way for this to work on the main page as well.
I figured out that adding this little bit of code:
$wp_query->is_single = true;
basically this will tell WP to treat the current page as a single page, even if it’s your home page or main page with multiple posts on the page.
Sweet, get_adjacent_post() is what I need as well. Thanks!
how does “$excluded_categories” work?