Suite au billet DotClear mis à la page, je me risque à partager mon système de pagination pour une installation standard utilisant le thème par défaut...

Tout d'abord, assurez-vous que vous utilisez bien des URL de type "path_info". Si ce n'est pas le cas, les modifications qui suivent ne fonctionneront pas. Ensuite, faites impérativement une sauvegarde de vos fichiers. Une erreur est si vite arrivée...

Ouvrez le fichier ./inc/classes/class.blog.php

Trouvez
function SQL($reqPlus='',$order='post_dt ASC',$limit='')
Remplacez par
function SQL($reqPlus='',$order='post_dt ASC',$limit='', $limit2=0)

Trouvez
if ($limit != '') {
  $limit = (preg_match('/^[0-9]+$/',$limit)) ? '0,'.$limit : $limit;
  $strReq .= 'LIMIT '.$limit.' ';
}
Remplacez par
if ($limit != '') {
  if ($limit2 != 0 )
  $limit = (preg_match('/^[0-9]+$/',$limit)) ? intval($limit2).','.$limit : $limit;
  $strReq .= 'LIMIT '.$limit.' ';
}

Remplacez ensuite la fonction getLastNews() par le code suivant :

nouvelle fonction getLastNews
function getLastNews($limit=20,$cat='',$order='post_dt DESC',$selected=false,$lang='')
{
  global $max_nbr_pages, $num_current_page;
  
  $reqPlus = '';
  
  if ($cat != '') {
    if (preg_match('/^[0-9]+$/',$cat)) {
      $reqPlus .= 'AND C.cat_id = '.$cat.' ';
      $strCountReq = 'SELECT COUNT(post_id) as nbr FROM '.$this->t_post.' P, '.$this->t_categorie.' C WHERE P.post_pub = 1 AND P.cat_id =C.cat_id AND C.cat_id=' . $cat;
    } else {
      $reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
      $strCountReq = 'SELECT COUNT(post_id) as nbr FROM '.$this->t_post.' P, '.$this->t_categorie.' C WHERE P.post_pub = 1 AND P.cat_id =C.cat_id AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
    }
  }
  else
  {
    $strCountReq = 'SELECT COUNT(post_id) as nbr FROM '.$this->t_post.' WHERE post_pub = 1';
  }
  $from = 0;
  if ( !isset($max_nbr_pages) && !strpos($_SERVER['SCRIPT_FILENAME'], '/ecrire/') )
  {
    if ( (($rs = $this->con->select($strCountReq)) !== false ) && !$rs->isEmpty() )
    {
      $max_nbr_news = intval($rs->field('nbr'));
      $max_nbr_pages =  ($max_nbr_news<=1 || $limit<=0) ? 1 : ceil($max_nbr_news / $limit);
      $num_current_page = !empty($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
      if ($num_current_page<=1) $num_current_page = 1;
      else if ($num_current_page> $max_nbr_pages) $num_current_page = $max_nbr_pages;
          
      $from = $limit * ($num_current_page-1);
    }
  }
  
  if ($selected) {
    $reqPlus .= 'AND P.post_selected = 1 ';
  }
    
  if ($lang != '') {
    $reqPlus .= 'AND P.post_lang = \''.$this->con->escapeStr($lang).'\' ';
  }
  $strReq = $this->SQL($reqPlus,$order,$limit, $from);
    
  if (($rs = $this->con->select($strReq,$this->rs_blogpost, false)) !== false) {
    $rs->setBlog($this);
    return $rs;
  } else {
    $this->setError('MySQL : '.$this->con->error(),2000);
    return false;
  }
}

Remplacez également la fonction getPostByDate() par le code suivant :

nouvelle fonction getPostByDate()
function getPostByDate($y,$m,$d='',$cat='',$order='post_dt DESC',$selected=false,$lang='')
{
  global $max_nbr_pages, $num_current_page;
  $reqPlus = 'AND DATE_FORMAT(post_dt,\'%Y\') = \''.(integer) $y.'\' ';
  $reqPlus .= 'AND DATE_FORMAT(post_dt,\'%c\') = \''.(integer) $m.'\' ';
    
  if ($d != '') {
    $reqPlus .= 'AND DATE_FORMAT(post_dt,\'%e\') = \''.(integer) $d.'\' ';
  }
    
  if ($cat != '') {
    if (preg_match('/^[0-9]+$/',$cat)) {
      $reqPlus .= 'AND C.cat_id = '.$cat.' ';
    } else {
      $reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
    }
  }
    
  if ($selected) {
    $reqPlus .= 'AND P.post_selected = 1 ';
  }
    
  if ($lang != '') {
    $reqPlus .= 'AND P.post_lang = \''.$this->con->escapeStr($lang).'\' ';
  }
    
  $from = 0; $limit = NULL;
  if ( !strpos($_SERVER['SCRIPT_FILENAME'], '/ecrire/') )
  {
    $strCountReq = 'SELECT COUNT(post_id) as nbr FROM '.$this->t_post.' P, '.$this->t_categorie.' C WHERE P.post_pub = 1 AND P.cat_id =C.cat_id '. $reqPlus;
    $limit = dc_nb_post_per_page;
    if ( !isset($max_nbr_pages) )
    {
      if ( (($rs = $this->con->select($strCountReq)) !== false ) && !$rs->isEmpty() )
      {
        $max_nbr_news = intval($rs->field('nbr'));
        $max_nbr_pages =  ($max_nbr_news<=1 || $limit<=0) ? 1 : ceil($max_nbr_news / $limit);
        $num_current_page = !empty($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
        if ($num_current_page<=1) $num_current_page = 1;
        else if ($num_current_page> $max_nbr_pages) $num_current_page = $max_nbr_pages;
        
        $from = $limit * ($num_current_page-1);
      }
    }
  }
    
  $strReq = $this->SQL($reqPlus,$order, $limit, $from);
  if (($rs = $this->con->select($strReq,$this->rs_blogpost, false)) !== false) {
    $rs->setBlog($this);
    return $rs;
  } else {
    $this->setError('MySQL : '.$this->con->error(),2000);
    return false;
  }
}

Ouvrez le fichier ./layout/lib.mod.php

Trouvez 2 fois
[0-9]{2})(/|\z)
Remplacez 2 fois par
[0-9]{2})(/|\z|\?)

Il ne vous reste plus qu'à mettre à jour le fichier prepend.php de votre thème et éventuellement votre feuille de style (fichier : pagination.zip). un simple appel à la fonction pagination() dans votre fichier list.php permet alors de faire apparaître le systèùe de pagination.

list.php
<?php endwhile; ?>
<?php pagination(); ?>

Si vous appliquez cette modification sur votre blog, pensez à le signaler ici :)