我正在joomla中实现分页。以下是代码
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('c.*,cat.alias as catalias')
->from('#__content AS c')
->from('#__categories AS cat')
->where('c.catid=19','AND')
->where('c.state=1','AND')
->where('c.catid = cat.id')
->order('c.created '.' ASC');
$db->setQuery($query,0,5);
$results = $db->loadAssocList();
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pager= new JPagination($db->loadResult(), 0, 2);
foreach ($results as $res) {
echo $res['id'];
....
.....
}
echo $pager->getListFooter();
这显示页脚的页码(如带有超链接的1 2 3)基于页面限制(3页中的6个记录(页数限制2))。但是所有记录都显示在单页中。不是每个记录中有两个记录页。
这里有什么需要改变。请帮助我。
提前致谢
答案 0 :(得分:2)
我得到了我的问题的解决方案:
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$limit = $app->getUserStateFromRequest("$option.limit", 'limit', 2, 'int');
$limitstart = $app->input->get('limitstart', 0, 'INT');
$query = $db->getQuery(true)
->select('SQL_CALC_FOUND_ROWS c.*,cat.alias as catalias')
->from('#__content AS c')
->from('#__categories AS cat')
->where('c.catid=19','AND')
->where('c.state=1','AND')
->where('c.catid = cat.id')
->order('c.created '.' ASC');
$db->setQuery($query,$limitstart, $limit);
$results = $db->loadAssocList();
if(!empty($results)){
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pager= new JPagination($db->loadResult(), $limitstart, $limit);
foreach ($results as $res) {
echo $res['id'];
YOUR_CODE_HERE
}
echo $pager->getListFooter();
}
答案 1 :(得分:0)
如果要更改默认文章分页,则必须覆盖分页内容插件的默认模板。