Jump to content

Module want: Next and Previous Links


Alexander
 Share

Recommended Posts

to give you a starting point, this is the code snippet from the page i´ve posted

<?php 
  include('./includes/head.php'); 
  $options = array(
    'nextItemLabel' => "Weiter",
    'previousItemLabel' => "Zurück",
    'listMarkup' => "<div class='pagination pagination-centered'><ul>{out}</ul></div>",
    'currentItemClass' => "active disabled",
    'itemMarkup' => "<li class='{class}'>{out}</li>",
    'linkMarkup' => "<a href='{url}'>{out}</a>"
  );
  $items = $page->children("limit=10"); 
  $pagination = $items->renderPager($options); 
  echo $pagination; 
?>
  • Like 1
Link to comment
Share on other sites

Thanks Mats and Luis for your help and time.
 
I trying to use $page->next, but in my case it returns only numbers.
 
I findet in blog demo this code and it's work perfect.
function renderNextPrevPosts($page) {
	$bedroom = $page->getUnformatted('bedroom');
	$nextPost = $page->parent->child("bedroom>$bedroom, sort=bedroom");
	$prevPost = $page->parent->child("bedroom<$bedroom, sort=-bedroom");

	$out = "<div class='next-prev-posts'>"; 
	if($prevPost->id > 0) $out .= "<p class='prev-post'><span><</span> <a href='{$prevPost->url}'>{$prevPost->title}</a></p>";
	if($nextPost->id > 0) $out .= "<p class='next-post'><a href='{$nextPost->url}'>{$nextPost->title}</a> <span>></span></p>";
	$out .= "</div>";
	return $out; 
}
Link to comment
Share on other sites

The $page's next and prev functions return the next and previous sibling, according to whatever sort settings you have defined with the parent. However, you could still do it like this:

$siblings = $page->siblings("sort=date"); // or whatever you want to sort by 
$next = $siblings->getNext($page); 
$prev = $siblings->getPrev($page); 

if($prev) echo "<a href='$prev->url'>Prev</a> ";
if($next) echo "<a href='$next->url'>Next</a> ";

Personally, I prefer using regular pagination to something like this. The skyscrapers profile has some good examples of using pagination with custom sorts. 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...