Page 1 of 1

Next / Previous pages

Posted: Sun Jan 12, 2020 9:48 pm
by bayerberg
I'm doing next/ previous pages this way

Code: Select all

echo'<div class="row">';

	$previousPageKey = $page->previousKey();
	$previousPage = buildPage($previousPageKey);
	$nextPageKey = $page->nextKey();
	$nextPage = buildPage($nextPageKey);

	echo'<div class="six columns center-text">';
	echo '<p class="title">Next post: <br/>  ';
	if ($page->nextKey()) {
		echo'&#8729; <a href="'.$nextPage->permalink().'">'.$nextPage->title().'</a>';
		echo'<div class="hovering-button left"><a href="'.$nextPage->permalink().'" >&laquo;</a></div>';
	} else {
	echo 'Hold your horses, this is the latest post';
	}
	echo'</p>';
	echo'</div>';
	echo'<div class="six columns center-text">';
	echo '<p class="title">Previous post: <br/> &#8729; ';
	if ($page->previousKey()){
		echo'<a href="'.$previousPage->permalink().'">'.$previousPage->title().'</a>';
		echo'<div class="hovering-button right"><a href="'.$previousPage->permalink().'" >&raquo;</a></div>';
		} else {
		echo ' No more posts. You reached the end.';
	}
	echo'</p>';
	echo'</div>';
	
echo'</div>';
and sometimes I wont get either one. Whats the issue? Looks ok to me...

Re: Next / Previous pages

Posted: Fri Jan 31, 2020 12:44 am
by bayerberg
Managed to track down the issue - it has to do something with a date and how its being set. Theres a time difference between my server and what Bludit sets on published posts. Any help?

Re: Next / Previous pages

Posted: Fri Jan 31, 2020 8:30 pm
by Edi
bayerberg wrote: Fri Jan 31, 2020 12:44 am Theres a time difference between my server and what Bludit sets on published posts.
What is the difference? What about setting another time zone in Bludit?

Re: Next / Previous pages

Posted: Fri Jan 31, 2020 10:17 pm
by bayerberg
its not a timezone issue. time difference is around 20 minutes. it happens both on a local server and online.

Re: Next / Previous pages

Posted: Tue Feb 04, 2020 9:35 am
by diego
Hi,
maybe there is a bug on the function next and prev pages, I will check.
Have you tried to print the values or make a small example, I mean create 4 pages and check if the values returned is correct?

Re: Next / Previous pages

Posted: Tue Feb 04, 2020 12:19 pm
by diego
I tried the functions and works fines.

Code: Select all

<?php
if ($WHERE_AM_I=='page') {
	if ($page->nextKey()) {
		$nextPage = buildPage($page->nextKey());
		echo "The title of the next page: ".$nextPage->title().'<br>';
	} else {
		echo "There is not next page.".'<br>';
	}
	
	if ($page->previousKey()) {
		$prevPage = buildPage($page->previousKey());
		echo "The title of the previous page: ".$prevPage->title().'<br>';
	} else {
		echo "There is not previous page.".'<br>';
	}
}
?>

Re: Next / Previous pages

Posted: Thu Feb 06, 2020 2:57 pm
by bayerberg
thanks for checking. the bug is there somewhere :) i get the issue quite often, dont have a clue why it happens though. ill post up the example when it happens.

Re: Next / Previous pages

Posted: Mon Feb 24, 2020 5:01 pm
by bayerberg
diego wrote: Tue Feb 04, 2020 12:19 pm I tried the functions and works fines.
@diego ha! happened again - https://dontbe.soy/
json looks ok but the site mangles previous/ next pages. first one doesn't have any, then next two sit together and then the rest of the page works as normal. there might be a wonky loop somewhere, trying to find it.

Re: Next / Previous pages

Posted: Tue Feb 25, 2020 6:05 pm
by bayerberg
ha! looks like page type might have something to do with it - had a bunch of drafts and when I deleted them everything went back to normal!

Re: Next / Previous pages

Posted: Thu Apr 06, 2023 8:51 pm
by haywardgg
bayerberg wrote: Tue Feb 25, 2020 6:05 pm ha! looks like page type might have something to do with it - had a bunch of drafts and when I deleted them everything went back to normal!
Did you ever get this working reliably ?

For me it's random. I'll post several pages and they all work fine , the next and previous links work as expected. But I'll edit a page or change the post date or something and the next or previous link for that page will break, even though there's pages both sides in the cue. I can sometimes fix it by changing the date of the post to a few days in the past, but then that defeats the object of a blog imho.

The code I'm using for the next and previous links. https://gist.github.com/haywardgb/47118 ... bec31fe5a5

Any ideas ? I've not got any drafts and like I said it works one minute then for no apparent reason the next page will break the links.. No erros in the logs or debug!