Documentation

Light-weight, fast, simple and powerful!
 
Translations of this page?:

Pager.php helper

This helper was contributed by jMas

The default Pagination helper included with Wolf is based on the Code Igniter framework. This alternative pagination helper comes from the Kohana framework.

Code

Download the pager.zip file, unzip, and save “Pager.php” (use of capital “P” is mandatory) in your wolf/helpers folder.

Usage

The following notes explain how to use Pager.php with the default Wolf “Articles” page. Adjustments can be made from this code for paginating other subpages as well.

1. Set up Pager

Put this code at the top of the parent page of the pages you want paginated (note: all the code in these instructions goes into the same page):

<?php use_helper('Pager'); 
$pager = new Pager(array(
    'style' => 'classic', // other styles are available
    'items_per_page' => 3, // set this to number of your choice
    'total_items' => $this->childrenCount()
)); ?>

The only thing you need to change here is the items_per_page to the value of your choice.

2. Calling pages to paginate

<?php $last_articles = $this->children(array('limit' => $pager->items_per_page, 'offset' => $pager->sql_offset, 'order'=>'page.created_on DESC')); ?>

3. Loop through the pages

<?php foreach ($last_articles as $article): ?>
<div class="entry">
  <h3><?php echo $article->link($article->title); ?></h3>
  <?php // and whatever else you want to include here! ?>
</div>
<?php endforeach; ?>

4. Call the pagination links

<?php echo $pager; ?>

Options

Several different link styles are included with Pager.php; give the style you want to use in the “setup” code (step #1, above):

name output
classic ‹ First < 1 2 3 > Last ›
digg « Previous 1 2 … 5 6 7 8 9 10 11 12 13 14 … 25 26 Next »
extended1) « Previous ¦ Page 2 of 11 ¦ Showing items 6-10 of 52 ¦ Next »
punbb Pages: 1 … 4 5 6 7 8 … 15

Clean URL support

For Pager to produce clean URLs in the form http://example.com/page/xxx, follow these two steps:

1. Change one line in the Pager.php helper (line 81):

// Create full URL
$this->url = "/page/{page}";

2. And add this line in to the .htaccess file:

# Pagination
RewriteRule page/([0-9]+)$ index.php?page=$1

(Thanks to ZenZen for supplying this enhancement in the forum.)

Further help

If you need further help to get Pager.php working, or have questions about it, please use the Pager thread in the Wolf forums.

1) This style uses a solid bar/pipe character, not the broken one which is used by necessity here because of the Dokuwiki markup syntax.
 
helpers/pager.txt · Last modified: 2011-09-12 00:46 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside