Digg Style Pagination Class

Inicio ¿Sidebar? RSS @MisAlgoritmos at Twitter

Digg Style Pagination Class

Based on the modular version for the pagination, now I have created a version easier to implement, using classes for PHP version 4. The implementation is simple, is necessary to include the class with a require or an include. We defined basic properties for pagination such as an amount of elements to paginate, elements by page, page to which the element "page" will be sent, you need a CSS style and finally we generate the pagination to show it.

If you're looking for how to paginate your SQL query? This other entry is for you: How to paginate your SQL querys.

  1. include(ABSPATH.'/includes/pagination.class.php');
  2. /*
  3. Now you can work with de pagination class
  4. */
The class.
  • Download Version 0.4.1 (2008-04-11)
    1. Added getOutput() function.
  • Version 0.4 (2007-10-21)
    1. Added class next and prev to next and prev buttons.
    2. Bug fix
  • Version 0.3.3 (2007-10-05)
    1. Possibility to set 0 as the current page (no page selected). Back and Next buttons won't be shown.
  • Version 0.3.2 (2007-09-19)
    1. Changed round to ceil (line 122)
  • Version 0.3.1 (2007-08-23)
    1. Changed ceil to round (line 122)
  • Version 0.3 (2007-07-10)
    1. Added the URL friendly functionality.
  • Version 0.2 (2007-06-15)
    1. show an error and description if the function was called wrongly.
    2. Sends & instead of ? if the current file has vars in $_GET
    3. can change the name of the parameter ?page=
    4. there is no necessary to calculate in a manual way the pagination ($class->calculate()), is automatically when you show it the first time
    5. and others functionalities
  • Version 0.1 (2007-05-27)
    • First version

Dowload and unrar where you will work with the class. For the CSS, you can take one fromthis list.

If you forget a parameters to show or calculate the pagination. The class will show you a error to remember that. by example:

  1. $p=new pagination();
  2. $p->show();

the results:

It is necessary to specify the number of pages ($class->items(1000))
It is necessary to specify the limit of items to show per page ($class->limit(10))

by default, the target of the pagination link is the same file where the paginations is showed. you can change it. using $class->target(file)

  1. $p = new pagination;
  2. $p->items(1000);
  3. $p->limit(10);
  4. $p->target("?foo=var");
  5. $p->show();
« Previous1234567...99100

You can change the name of the parameter that brings the current page value. Using the $class->parameterName("p") you will see how the links changes the target to ?p=X instead of ?page=X

  1. $p = new pagination;
  2. $p->items(1000);
  3. $p->limit(10);
  4. $p->currentPage(1);
  5. $p->parameterName("p");
  6. $p->show();
« Previous1234567...99100

Defining the pagination on its basic way, specifying an amount of items, limits of items by page, the pointed file by the pagination and the number of the present page.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(2);
  6. $p->show();

Defining in 1 the amount of adjacent pages to the present page.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(50);
  6. $p->adjacents(1);
  7. $p->show();

Defining in 3 the amount of adjacent pages to the present page.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(50);
  6. $p->adjacents(3);
  7. $p->show();

Defining in 4 the amount of adjacent pages to the present page.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(50);
  6. $p->adjacents(4);
  7. $p->show();

Activating the functionality to show the pages amount.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(6);
  6. $p->showCounter(true);
  7. $p->show();

Changing the text of the navigation tags and removing the icons.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(7);
  6. $p->nextLabel('<strong>Siguiente</strong>');//changing next text
  7. $p->prevLabel('<strong>Anterior</strong>');//changing previous text
  8. $p->nextIcon('');//removing next icon
  9. $p->prevIcon('');//removing previous icon
  10. $p->show();

Removing the text of the navigation tags.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(8);
  6. $p->nextLabel('');
  7. $p->prevLabel('');
  8. $p->show();

Changing the icons of the navigation tags

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("paginator.php");
  5. $p->currentPage(9);
  6. $p->nextIcon('&#9658;');
  7. $p->prevIcon('&#9668;');
  8. $p->show();

Removing the text of the navigation tags and changing the icons.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("#");
  5. $p->currentPage(10);
  6. $p->nextLabel('');//removing next text
  7. $p->prevLabel('');//removing previous text
  8. $p->nextIcon('&#9658;');//Changing the next icon
  9. $p->prevIcon('&#9668;');//Changing the previous icon
  10. $p->show();

Changing the div class (<div class="class">Pagination</div>) that surrounds the pagination (to manipulate many CSS styles)

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->target("#");
  5. $p->currentPage(11);
  6. $p->changeClass("jogger");
  7. $p->show();
  8. $p->changeClass("tres");
  9. $p->show();
  10. $p->currentPage(14);
  11. $p->changeClass("meneame");
  12. $p->show();
« Previous1234567...99100
« Previous1234567...99100

To use the URL friendly, we need to execute the function $p->urlFriendly();. So we need to add to the $p->target("#"); the placeholder % where we need the page numbers. If we need to change the placeholder, we can do it send it the desired char as parameter to the function $p->urlFriendly('[...]');, and to the $p->target("#[...]");.

  1. $p = new pagination;
  2. $p->Items(1000);
  3. $p->limit(5);
  4. $p->currentPage(14);
  5.  
  6. $p->urlFriendly();
  7. $p->target("#page/%/");//#page/1/
  8. $p->show();
  9.  
  10. $p->urlFriendly('[...]');
  11. $p->target("#pagina/[...]/");//#pagina/1/
  12. $p->show();
  13.  
  14. $p->urlFriendly(false);
  15. $p->target("#");//#page=1
  16. $p->show();
« Previous1234567...99100
« Previous1234567...99100
« Previous1234567...99100
There are 87 comments. for this entry.