File: example.php

Recommend this page to a friend!
  Classes of djomla  >  Paginate simple  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example - howto - usage
Class: Paginate simple
Generate links for paginating listings
Author: By
Last change:
Date: 9 years ago
Size: 1,868 bytes
 

Contents

Class file image Download
<?php
include ("Paginate.php");

$pagination = new Paginate (array(
                           
'numItems' => 10, // number of results
                           
'perPage' => 2, // items you want to display per page
                           
'url' => '/list_my_results.php?page=' // url for pagination
                       
));
$paginater = $pagination->dispatch();

# And now methods ##
$pagination->hasPrevPage(); // returns boolean
$pagination->getPrevPage()->getLink();
$pagination->getPrevPage()->getNumber();
$pagination->getFirstPage()->getLink();
$pagination->getLastPage();

$pagination->getDisplayPages(); // returns array of PaginatePage objects
$pagination->getCurrentPage(); //

## Now i will display smarty template i use for pagination ##


<div id="pagination">
    {if
$pagination->hasPrevPage()}
        <
a href="{$pagination->getPrevPage()->getLink()}" title="« Previous">« Previous</a>
    {else}
        <
span class="disabled">« Previous</span>
    {/if}

    {if
$pagination->getCurrentPage-3 > 1}
        <
a href="{$pagination->getFirstPage()->getLink()}" title="{$pagination->getFirstPage()->getNumber()}">{$pagination->getFirstPage()->getNumber()}</a>
    {/if}

    {foreach
from=$pagination->getDisplayPages() item=dpage}
        {if
$pagination->getCurrentPage() == $dpage->getNumber()}
            <
span class="active">{$dpage->getNumber()}</span>
        {else}
            <
a href="{$dpage->getLink()}" title="{$dpage->getNumber()}">{$dpage->getNumber()}</a>
        {/if}
    {/foreach}

    {if
$pagination->getCurrentPage()+3 < $pagination->getTotalPages()}
        <
a href="{$pagination->getLastPage()->getLink()}" title="{$pagination->getLastPage()->getNumber()}">{$pagination->getLastPage()->getNumber()}</a>
    {/if}

    {if
$pagination->hasNextPage() AND $pagination->getTotalPages() > $pagination->getCurrentPage()+3}
        <
a href="{$pagination->getNextPage()->getLink()}" title="Next »">Next »</a>
    {else}
        <
span class="disabled">Next »</span>
    {/if}
</
div>

?>


For more information send a message to info at phpclasses dot org.