General
Getting & Giving Support
Administration
Design
- Tut. - Layouts and Themes
- Tut. - Navigation cookbook
- Tut. - How To section
Reference Material
Plugin Development
- Tut. - Writing a plugin
- Ref. - List of Events
- Ref. - Enabling cron jobs
- Ref. - PHPDoc
Core Development
- Ref. - PHPDoc
Press information
Wolf CMS books section
Pagination.php helper
Introduction
The default pagination helper which comes with Wolf is a light revision of the the Code Igniter pagination helper. It allows multiple pages to be listed as a set of page links in the form:
Pages: 1 2 3 4
The notes that follow explain how to set up Pagination.php for use with the default “Articles” page in Wolf CMS, but can be modified for use with other pages as well. Be aware that for the Set up, the code varies depending on whether mod_rewrite is enabled or disabled. The notes assume mod_rewrite is enabled, with the disabled version given as a variation.
Usage
1. Call objects to Paginate
Open the Articles page for editing: this is the only page used for these instructions. This first thing to do at the top of the page, is call the “page objects” you wish to paginate:
<?php $last_articles = $this->children(array('limit'=>5, 'offset'=>($pagination->cur_page)*($pagination->per_page), 'order'=>'page.created_on DESC')); ?>
Here, note that limit should be the same value as the per_page value in the set up of step #3, below. The offset code is required by the helper to form the links properly, but takes its values from the pagination set up.
2. Loop through the pages
<?php foreach ($last_articles as $article): ?> <div class="entry"> <h3><?php echo $article->link($article->title); ?></h3> <?php // Whatever else you want to include: teaser? meta? etc. ?> </div><!-- end .entry --> <?php endforeach; ?>
3. Set up helper
At this point, call the helper, and set the options (if this code block is put at the top of the page, the offset will not work properly):
<?php use_helper('Pagination'); $pagination = new Pagination(array( 'base_url' => '/articles?page=', 'total_rows' => $this->childrenCount(), 'per_page' => 5, 'num_links' => 8, 'cur_page' => (isset($_GET['page']) ? $_GET['page']: 1) )); ?>
Only three of those lines might require adjustment:
base_url- include the slug of the current page (here, “articles”), which is the parent of the pages you wish to paginate, followed by?page=
If mod_rewrite is disabled, then add another ”?” after the initial slash:/?articles?page=per_page- the number of sub-pages linked on each paginated pagenum_links- when this number of page links is exceeded, a “First” and “Last” link will be added to the left and right of the number list.
4. Call pagination links
<?php if ($pagination->total_rows > $pagination->per_page) echo '<p><br />Pages: '.$pagination->createLinks().'</p>'; ?>
You can vary the <p> and <br /> markup to suit your layout. Now save the Articles page. Done!
Alternate helper
For a different, alternative pagination helper, see the Pager documentation.
