Created
January 30, 2011 13:22
-
-
Save dajare/802854 to your computer and use it in GitHub Desktop.
Advanced Find with Pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* For use in a page with WolfCMS - http://www.wolfcms.org | |
* Uses mtylerb's Advanced Find, and the Pager helper to paginate results | |
* AdvancedFind - https://github.com/mtylerb/adv-find | |
* Pager - http://www.wolfcms.org/wiki/helpers:pager | |
*/ | |
// USE THIS FOR DYNAMIC ADDITION OF BRANCHES TO ADVFIND | |
$categories = array(); | |
foreach ($this->find('/')->children() as $child) { | |
if (count($this->find($child->slug())->children()) > 0) { | |
array_push($categories,$child->slug()); | |
} | |
} | |
?> | |
<?php // get all the articles we want to paginate with AdvancedFind: | |
$all_articles = adv_find( | |
/** | |
* UNCOMMENT EITHER LINE 25 _OR_ LINE 26 | |
* - use "array()" for manual addition of slugs; | |
* - use "$categories" for dynamic array of pages. | |
*/ | |
// array('news/', 'articles/'), | |
// $categories, | |
array('order' => 'published_on DESC')); // ASC or DESC | |
?> | |
<?php use_helper('Pager'); // set up Pager... | |
$pager = new Pager(array( | |
'style' => 'classic', // other styles are available | |
'items_per_page' => 4, // set this to number of your choice | |
'total_items' => count($all_articles) | |
)); ?> | |
<?php // make sure number before "true" = "items_per_page" set above: | |
$last_articles = array_slice($all_articles, $pager->sql_offset, 4, true); ?> | |
<?php foreach ($last_articles as $article) : // loop through our items: ?> | |
<div class="entry"> | |
<h3><?php echo $article->link(); ?></h3> | |
<p class="info">Posted by <?php echo $article->author(); ?> | posted on <?php echo $article->date(); ?></p> | |
</div> | |
<?php endforeach; ?> | |
<?php echo $pager; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment