gilbitron/Pico — pull request #18 by ibes (2013-05-04 23:37:59+00:00)
Title: fixed prev/next page - didnt showed next_page if prev_page dont exist

right now, when you use prev_page and next_page the "next_page" has the dependency that there is a "prev_page" else the next_page can't be calculated.

$prev_page = next($pages); // might be "false" and the next two lines won't work
prev($pages);
$next_page = prev($pages);

solve this with:

$next_page = current($pages); // next_page is first page in the queue
while($current_page = current($pages)){
if($meta['title'] == $current_page['title']){
if ($next_page['title'] == $current_page['title']){ // that is only possible in the first run of the "while()" so $current_page is first page in the queue
$next_page = array(); // so no $next_page
}
break;
}
$next_page = current($pages); // set $next_page to the page, that will be the previous page when the next line runs
next($pages);
}
$prev_page = next($pages);

It's a bit confusing that the next page is generated via "prev()" and the previous page is generated via "next()"...