Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to limit the function of paging down to stop at number 10? Eg: pages: 1 2 3 4 5 6 7 8 9 10.

function kriesi_pagination($pages = '', $range = 2)
{  
 $showitems = ($range * 2)+1;  

 global $paged;
 if(empty($paged)) $paged = 1;

 if($pages == '')
 {
     global $wp_query;
     $pages = $wp_query->max_num_pages;
     if(!$pages)
     {
         $pages = 1;
     }
 }   

 if(1 != $pages)
 {
     echo "<div class='pagination'>";
     if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
     if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

     for ($i=1; $i <= $pages; $i++)
     {
         if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
         {
             echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
         }
     }

     if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
     if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
     echo "</div>\n";
 }
}

I appreciate any help.

share|improve this question
    
Do you mean to completely stop and #11 and up should be never linked and shown or to limit simultaneously shown pages to 10? –  Max Yudin Jul 18 '12 at 8:11
add comment

2 Answers

up vote 2 down vote accepted
for ($i=1; $i <= min($pages,10); $i++)
share|improve this answer
    
Perfect @Michael. It was probably easy enough for you, lol. I confess: I'm just a beginner in php. –  BóbGCA Jul 18 '12 at 15:40
add comment

try this

for ($i=1; $i <= $pages; $i++)
{
   if($i >= 11) break;

 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
         {
             echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
         }
}
share|improve this answer
    
Thank @AnupRaj. Unfortunately there appears to be a bug in that code, all disappeared number, and was only 11 (pages: 11). –  BóbGCA Jul 18 '12 at 15:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.