/** * Smarty page modifier plugin * * Type: modifier<br> * Name: page<br> * Date: JUNE 19, 2008 * Purpose: get page list by count * Input: count int * Input: page_size int * Example: {$count|page:20} * @version 1.0 * @param (int) $count | 分页的总数 * @param (int) $page_size | 每页多少条记录 * @return (String) 分页字符串 */ function smarty_modifier_page($count, $page_size = 20) { $count = intval($count); $page_size = intval($page_size); $pager = new Pager(array('rowCount' => $count, 'pageSize' => $page_size)); return $pager->genYuan(); }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/../init.inc.php'; Template::SetTitle('首页'); $params = array('condition' => array(), 'order' => array()); define('PAGE_SIZE', 1); $p = intval($_GET["p"]) ? intval($_GET["p"]) : "1"; $offset = PAGE_SIZE * ($p - 1); $indexType = ContentList::getList($params, $offset, PAGE_SIZE); $totalcount = $indexType['count']; $pager = new Pager(array('pageSize' => PAGE_SIZE, 'rowCount' => (int) $totalcount)); Template::assign('indexType', $indexType['list']); Template::assign('pager', $pager->genYuan()); Template::assign('usernames', $usernames); Template::display('pager.tpl');