SPIP - Contrib

SPIP - Contrib

[ar] [en] [es] [fr] [it]

70 visiteurs en ce moment

fontsizeup fontsizedown

PaginationAvecMaxEtMin

vendredi 29 avril 2005

  • Digg
  • Del.icio.us
  • Facebook
  • Google
  • Technorati

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 '';
}

Répondre à cet article

Retour en haut de la page

Ça discute par ici

SPIP | Squelette | | Plan du site | Suivre la vie du site RSS 2.0