PaginationAvecMaxEtMin

All contributions published for previous SPIP versions

Variant de JMax pour son blog : des boutons précédent, suivants, premier, dernier...

function pagination($total, $position=0, $pas=1, $fonction='') {
 global $clean_link;
 global $pagination_item_avant, $pagination_item_apres, $pagination_separateur;
 tester_variable('pagination_separateur', ' | ');
 if (ereg('^debut([-_a-zA-Z0-9]+)$', $position, $match)) {
   $debut_lim = "debut".$match[1];
   $position = intval($GLOBALS['HTTP_GET_VARS'][$debut_lim]);
 }
 $nombre_pages = floor(($total-1)/$pas)+1;
 $texte = '';
 if($nombre_pages>1) {
   $firstposition = $total - $pas;
   if ($position < $firstposition){
     $clean_link->delVar($debut_lim);
     $clean_link->addVar($debut_lim, strval($firstposition));
     $first_link = $clean_link->getUrl();
     $first = " <a href="$first_link"> |< </a> ";
   } else $first = " |< ";
   if ($position > 0){
     $clean_link->delVar($debut_lim);
     $clean_link->addVar($debut_lim, strval(0));
     $last_link = $clean_link->getUrl();
     $last = " <a href="$last_link"> >| </a> ";
   } else $last = " >| ";
   if ($position > 0){
     if ($position <= $pas) $next_link = $last_link;
     else {
       $clean_link->delVar($debut_lim);
       $clean_link->addVar($debut_lim, strval($position-$pas));
       $next_link = $clean_link->getUrl();
     }
     $next = " <a href="$next_link"> >> </a> ";
   } else $next = " >> ";
   $prevposition=$position+$pas;
   if ($prevposition < $total){
     if ($prevposition > $total - $pas) $prev_link = $first_link;
     else {
       $clean_link->delVar($debut_lim);
       $clean_link->addVar($debut_lim, strval($prevposition));
       $prev_link = $clean_link->getUrl();
     }
     $prev = " <a href="$prev_link"> << </a>";
   } else $prev = " << ";
   $texte = $first . $prev . $next . $last;

//        Correction bug: $clean_link doit revenir à son état initial
   $clean_link->delVar($debut_lim);
   if($position) $clean_link->addVar($debut_lim, $position);
   return $texte;
 }
 return '';
}

updated on 5 March 2007

Discussion

Aucune discussion

Comment on this article

Who are you?
  • [Log in]

To show your avatar with your message, register it first on gravatar.com (free et painless) and don’t forget to indicate your Email addresse here.

Enter your comment here

This form accepts SPIP shortcuts {{bold}} {italic} -*list [text->url] <quote> <code> and HTML code <q> <del> <ins>. To create paragraphs, just leave empty lines.

Add a document

Follow the comments: RSS 2.0 | Atom