Fonction de pagination
function shop_pagination($total = true,$query = null,$pages = '', $range = 3) {
$showitems = ($range / 2)+1;
if($query==null){
global $wp_query;
$query = $wp_query;
}
global $paged;
if(empty($paged)) $paged = 1;
$i = $paged;
if($i >= 3){
//$e = ($paged - ($paged % 5));
$e = $paged - 2;
//echo $e;
$i = $e;
if($i <= 0){
$i = 1;
}
}else {
$i = 1;
}
if($pages == '')
{
$pages = $query->max_num_pages;
$maximun = $pages - 2;
if(!$pages)
{
$pages = 1;
}
}
echo "<div class='pagination'><p>Page ";
if($total){
echo"( $pages )";
}
echo " :</p>";
if(1 != $pages){
if($paged >= 2 ) echo "<a class='inactive' href='".get_pagenum_link(1)."'> « </a>";
if($paged >= 2) echo "<a class='inactive' href='".get_pagenum_link($paged - 1)."'> < </a>";
if($paged > 3){
for ($i; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+1 || $i <= $paged-$range-1) || $i <= $showitems )){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a class='inactive' href='".get_pagenum_link($i)."'>".$i."</a>";
}
elseif($i==($maximun-1)){
echo "<a class='inactive'>...</a>";
}
elseif($i>$maximun ){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a class='inactive' href='".get_pagenum_link($i)."'>".$i."</a>";
}
}
}else{
for ($i; $i <= $pages; $i++){
if(0 != $pages && $i <= $range &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $i <= $range )){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a class='inactive' href='".get_pagenum_link($i)."'>".$i."</a>";
}if($i==($maximun-1)){
echo "<a class='inactive'>...</a>";
}
elseif($i>=$maximun ){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a class='inactive' href='".get_pagenum_link($i)."'>".$i."</a>";
}
}
}
if ($paged < $pages && $showitems < $pages) echo "<a class='next' href='" . get_pagenum_link($paged + 1)."'> > </a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a class='next' href='".get_pagenum_link($pages)."'> » </a>";
}else{
}
echo "</div>";
}