Pour obtenir une navigation du type :
Pages : 1 2 3 ... 8 9 ... 14 15 16,
coller le code suivant dans le fichier _public.php du thème actif :
<?php
l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/main');
$core->tpl->addValue('PaginationLinks', array('tplMyPagination', 'PaginationLinks'));
class tplMyPagination {
public static function PaginationLinks($attr)
{
$p = '<?php
function makePageLink($pageNumber, $linkText) {
if (isset($GLOBALS["_page_number"])) {
$current = $GLOBALS["_page_number"];
} else {
$current = 1;
}
if ($pageNumber != $current) {
$args = $_SERVER["URL_REQUEST_PART"];
$args = preg_replace("#(^|/)page/([0-9]+)$#","",$args);
$url = $GLOBALS["core"]->blog->url.$args;
if ($pageNumber > 1) {
$url = preg_replace("#/$#","",$url);
$url .= "/page/".$pageNumber;
}
if (!empty($_GET["q"])) {
$s = strpos($url,"?") !== false ? "&" : "?";
$url .= $s."q=".$_GET["q"];
}
$linkDesc = $GLOBALS["__l10n"]["Go to page"]." ".$linkText;
return "<li><a href=\"".$url."\" title=\"".$linkDesc."\">".$linkText."</a></li>";
} else {
return "<li><span class=\"this\">".$linkText."</span></li>";
}
}
if (isset($GLOBALS["_page_number"])) {
$current = $GLOBALS["_page_number"];
} else {
$current = 1;
}
if ($_ctx->exists("pagination")) {
$nb_posts = $_ctx->pagination->f(0);
}
/* Variables to tweak the pagination system */
$nb_per_page = $_ctx->post_params["limit"][1];
$nb_pages = ceil($nb_posts/$nb_per_page);
$nb_sequence = 2 * 3 + 1;
echo "<ul>";
?>';
if (!isset($attr['max'])) { $p .= '<?php $nb_page_max = 0; ?>'; } else { $p .= '<?php $nb_page_max = '.$attr['max'].'; ?>'; }
$p .= '<?php
if ($nb_page_max == 0 || $nb_pages <= $nb_page_max) {
for ($i = 1; $i <= $nb_pages; $i++) {
echo makePageLink($i,$i);
}
} else {
echo makePageLink(1,1);
$min_page = max($current - ($nb_sequence - 1) / 2, 2);
$max_page = min($current + ($nb_sequence - 1) / 2, $nb_pages - 1);
if ($min_page > 2) { echo "<li><span class=\"etc\">...</span></li>"; }
for ($i = $min_page; $i <= $max_page ; $i++) {
echo makePageLink($i,$i);
}
if ($max_page < $nb_pages - 1) { echo "<li><span class=\"etc\">...</span></li>"; }
echo makePageLink($nb_pages,$nb_pages);
}
echo "</ul>";
?>';
return $p;
}
}
?>
Appeler ensuite cette fonction en collant la ligne suivante à l'endroit voulu :
{{tpl:PaginationLinks}}
On peut aussi passer un paramètre, pour limiter le nombre de pages, sous la forme :
{{tpl:PaginationLinks max="10"}}
Ajouter la traduction suivante dans le fichier locales/fr/main.lang.php du thème actif :
$GLOBALS['__l10n']['Go to page'] = 'Aller en page';
Ajouter la traduction suivante dans le fichier locales/fr/main.po du thème actif :
msgid "Go to page" msgstr "Aller en page"

