Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
When displaying a single post I have previous / next links. This works but I would like the 'next' link to point to the first post when the last post is displayed and the 'previous' link to point to the latest post when the first post is displayed. According to the documentation get_boundary_post() should be able to get the first or the last post. Here is what is in my single.php:

PHP
<?php
	$prev_post = get_adjacent_post( true, '', true );
	$next_post = get_adjacent_post( true, '', false );
	if($next_post == '')
	{
		$next_post = get_boundary_post();
	}
	if($prev_post == '')
	{
		$prev_post = get_boundary_post(); //???
	}
	$prev_post_id = $prev_post->ID;
	$next_post_id = $next_post->ID;   

<a href="<?php echo get_permalink($prev_post); ?>">previous</a>
<a href="<?php echo get_permalink($next_post); ?>">next</a>

?>


Getting the first post link for the last post works, but getting the latest post link for the first post doesn't. I'm not sure how to call get_boundary_post() to get the latest post, I've tried to set its 'start' parameter to false (default is true) but the link still points to the first post.
Posted

for next use 'true',
get_boundary_post($same_cat_do, $exclude_terms, true, $same_cat_category);

for prev use 'false'
get_boundary_post($same_cat_do, $exclude_terms, false, $same_cat_category);
 
Share this answer
 
Comments
Richard MacCutchan 2-Dec-22 7:31am    
I doubt that the questioner is still interested, ten years after posting the question.
Richard Deeming 2-Dec-22 7:37am    
But given the accepted solution points to a closed thread on another forum without any solutions, I don't think this question can really be considered "solved". :)
Richard MacCutchan 2-Dec-22 7:42am    
Solution 1 has been marked as accepted, so it's a reasonable assumption that OP was happy with the answer ten years ago.
Richard Deeming 2-Dec-22 8:30am    
Which seems rather odd. Perhaps the linked page has changed and the answer has been removed in the meantime.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900