Pagination - Vary Number Of Links To Index Pages

Permalink
At the bottom of the list for blog posts, C5 generates a list of pages. Using the default pagination block, the list generates numbers: 1,2,3,4,5,6...14 (last page).

You can find the default template in: concrete/blocks/page_list/templates/blog_index.php

Does anyone know how to the numbering at 5 and include links to pages 10 and 15 i.e:

1,2,3,4,5 > 10 > 15

I realise the function getPages() in: "concrete5.4.1.1/concrete/blocks/page_list/controller.php" returns the variable $pages. However, I'm not sure how to use it.

Many thanks for any help!

 
Shotster replied on at Permalink Reply
Shotster
Well, there's a setItemsPerPage() method that does just what it says. As for the links to pages 10 and 15, that might take some customizing - i.e. you might have to extend the PageList class or something. That might take a little digging to familiarize yourself with the class and its parent classes.

-Steve
cowland replied on at Permalink Reply
Had a look at the setItemsPerPage() method in the controller.php file. Changing that varies the amount of blog posts displayed on the index page itself.

To change the links to index pages you have to edit the file: concrete/helpers/pagination.php. The function getPages() on line 159 returns the string of links to other index pages.

You can change the total number of links displayed simply by changing the number added to "current_page" on line 172:

//following dots for high number of pages
         if($i>($this->current_page+5) && $i!=($this->number_of_pages-1)){
            if($postdotted!=1){
               $pages.='<span class="ccm-pagination-ellipses">...</span>';
               $postdotted=1;
            }
            continue;
         }


If you want to add your own links to the end you have to add a couple of if and for statements to ensure you don't count over the total "number_of_pages".

For example, if you copy and paste the following over the getPages() function: 1,2,3,4,5...10...15...93

function getPages(){
      if($this->number_of_pages==1) return;
      $pages_made=0;
      for ($i=0;$i<$this->number_of_pages;$i++){
         $pages_made=$pages_made+1;
         }
      for ($i=0;$i<$this->number_of_pages;$i++){
         //preceeding dots for high number of pages
         if($i<($this->current_page-4) && $i!=0){
            if($predotted!=1){
               $pages.='<span class="ccm-pagination-ellipses">...</span>';
               $predotted=1;
            }
            continue;
         }


Note that I moved $pages_made variable to a for loop at the top. I'm not sure what relevance it has so put it there.

This seems to do the job for now. However if you wanted to you could probably write it cleaner.
Shotster replied on at Permalink Reply
Shotster
Thanks, cowland. Sorry about the brain blip regarding items per page. As you discovered, it affects the number of retrieved items and not the pagination links. :-/

Thanks for posting your findings.

-Steve