Re: Another Pagination helper

Sorry guys, I wrote that while "on the run" as it were... big_smile

In fact, I've been running around all day including tonight so I'm of to bed. One last thought: I do think that ZenZen's original code *should* work as it did for him. It might depend on whether you have installed in a subdirectory or not.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

Re: Another Pagination helper

To make the pager work on a subpage change line 80 in the pager helper:

$this->url = "/subpage/page/{page}";
//make sure to change the name 'subpage' to the correct subpage for your site

If you have a subpage and subdomain do it like this:

$this->url = "/subdomain/subpage/page/{page}";
//make sure to change the name 'subpage' and 'subdomain' to the correct subpage and subdomain for your site

In your htaccess file put the code after the admin rewrite rule.

 RewriteRule ^(.*)/page/(.*)$ index.php?WOLFPAGE=$1&page=$2 [QSA]

The page links will display like this:
http://localhost/articles/page/2

Last edited by thewizardofbos (2011-04-25 19:29)

"When you want something, all the universe conspires in helping you to achieve it." - The Alchemist

28

Re: Another Pagination helper

I have got my Pager working on my Home page folder and getting this kind url: http://127.0.0.1/eripma/?articles.html?page=2

I know this is because I don't have the .htaccess configured on my local system.

Only got one strange thing. This is on my home. and i'm want to use the articles in the articles folder. But i'm also getting the articles from the other folders. When i'm on the second page (articles) everything works fine, even when you go back to page 1 you get all the articles.

But the frontpage gives a couple of content pages.

How can I change this to get this working? My code on the frontpage:

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


<?php 

$page_article = $this->find('/articles/');

if ($page_article->childrenCount() > 0) {
    $last_article = $page_article->children(array('limit'=>1, 'order'=>'page.created_on DESC'));
    //$last_articles = $this->children(array('limit'=>4, 'offset'=>($pagination->cur_page)*($pagination->per_page),  'order'=>'page.created_on DESC')); 
    $last_articles = $this->children(array('limit' => $pager->items_per_page, 'offset' => $pager->sql_offset, 'order'=>'page.created_on DESC'));
    
?>
<div class="first entry">
  <h3><?php echo $last_article->link(); ?></h3>
  <?php if (($more_pos = strpos($last_article->content(), '<!-- pagebreak -->')) === false ) {
  // "more" trigger NOT found, so just echo content
  echo $article->content();
} else {
  // "more" trigger IS found, so echo only teaser and add link to whole article
  echo substr($last_article->content(), 0, $more_pos);
  echo '</p><p>'. $last_article->link('Read more...') .'</p>';
} ?>
  
  
</div>

<?php foreach ($last_articles as $article):?>
<div class="entry">
  <h3><?php echo $article->link(); ?></h3>
   
  <?php if (($more_pos = strpos($article->content(), '<!-- pagebreak -->')) === false ) {
  // "more" trigger NOT found, so just echo content
  echo $article->content();
} else {
  // "more" trigger IS found, so echo only teaser and add link to whole article
  echo substr($article->content(), 0, $more_pos);
  echo '</p><p>'. $article->link('Read more...') .'</p>';
} ?>
  
</div>

<?php
    endforeach; 
}
?>
<?php echo $pager; ?>

Oké i've found the problem: chanced my code to this:

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


<?php 

$page_article = $this->find('/articles/');

if ($page_article->childrenCount() > 0) {
    //$last_article = $page_article->children(array('limit'=>1, 'order'=>'page.created_on DESC'));
    //$last_articles = $this->children(array('limit'=>4, 'offset'=>($pagination->cur_page)*($pagination->per_page),  'order'=>'page.created_on DESC')); 
    $last_articles = $page_article->children(array('limit' => $pager->items_per_page, 'offset' => $pager->sql_offset, 'order'=>'page.created_on DESC'));
    
?>
<!--<div class="first entry">
  <h3><?php //echo $last_article->link(); ?></h3>
  <?php //if (($more_pos = strpos($last_article->content(), '<!-- pagebreak -->')) === false ) {
  // "more" trigger NOT found, so just echo content
 // echo $article->content();
//} else {
  // "more" trigger IS found, so echo only teaser and add link to whole article
  //echo substr($last_article->content(), 0, $more_pos);
  //echo '</p><p>'. $last_article->link('Read more...') .'</p>';
//} ?>
  
  
</div>-->

<?php foreach ($last_articles as $article):?>
<div class="entry">
  <h3><?php echo $article->link(); ?></h3>
   
  <?php if (($more_pos = strpos($article->content(), '<!-- pagebreak -->')) === false ) {
  // "more" trigger NOT found, so just echo content
  echo $article->content();
} else {
  // "more" trigger IS found, so echo only teaser and add link to whole article
  echo substr($article->content(), 0, $more_pos);
  echo '</p><p>'. $article->link('Read more...') .'</p>';
} ?>
  
</div>

<?php
    endforeach; 
}
?>
<?php echo $pager; ?>

Last edited by Gix (2011-07-03 14:49)

Re: Another Pagination helper

Hello, WolfCMS Gurus!

I made the Pager Helper work at last. 
And I'd like to turn over the pages with the keyboard arrows.

I'm using the following  jquery code for inner pages and it works like a charm.

<!-- Arrows Keys -->
<script type="text/javascript">
        jQuery(document).ready(function () {
            $(document).keyup(function(e){
                if (e.which==37) {
                    $('<?php if ($next): ?>
                                <?php echo $next->link(); ?>
                                <?php endif; ?>').bind('click', function() { window.location.href = this.href; return false; }).trigger('click');
                } else if (e.which==39) {
                    $('<?php if ($previous): ?>
                                <?php echo $previous->link(); ?>
                                <?php endif; ?>').bind('click', function() { window.location.href = this.href; return false; }).trigger('click');
                };
            });
        });
</script>
<!-- Arrows Keys -->

I'm curious if anyone can help me to write two trigger for the next/previous links to work with pager helper.

Thanks in advance.

Last edited by mind-sparkle (2012-01-02 16:49)

Thumbs up

Re: Another Pagination helper

As you told us you've got a style like: "<previous 1 2 3 next>"

I guess you can just use a pure javascript like:

<script type="text/javascript">
  jQuery(document).ready(function () {
    $(document).keyup(function(e){
      // if left arrow key pressed
      if (e.keyCode == 37) {
        var href = $('.pager:first').find('a:first').attr('href');
        if(window.location.href != href)
          window.location.href = href;
      } 
      // if right arrow key pressed
      else if (e.keyCode == 39) {
        var href = $('.pager:first').find('a:last').attr('href');
        if(window.location.href != href)
          window.location.href = href;
        };
      });
  });
</script>

(above code is loose hand code, please check before use)

small note: Although it is possible, I strongly advise you to not do this! Using the arrow keys to navigate between pages is not something people expect to happen. The arrow keys are letting me scroll horizontally if possible. So going to the next page at the moment I press the right arrow key is really unwanted behavior.

//edit:
Verified It's working at this forum smile (injected with firebug). Just make sure to match the class name to your used pager class name! (wolfcms.org uses .pager for the plugin repository while using .paging for the forum.)

Last edited by s.meijer (2012-01-03 09:57)

Re: Another Pagination helper

Thank You very much smile

Thumbs up