我的分页限制是 5,每页有 5 个帖子。现在在第 1 页上我有 5 个帖子,但是当我转到第 2 页时,它会在第一页之后跳过 5 个帖子,并从帖子 #11 开始第二页,从第 2 页到结束,所有帖子都正确显示。然后最后一页是空的。(这意味着跳过了第 6 到 10 个帖子)
我尝试更改限制 $this->global_limit = 5; 到任何其他号码。问题仍然存在,例如如果我将限制更改为 10 个第一页将显示 10 个帖子,然后跳过第 11 到 20 个帖子并从第 21 页开始第 2 页。
/**
* Code in controller file
*/
$this->global_limit = 5;
$this->params['lang_id'] = $this->lang_id;
$this->params['limit'] = $this->global_limit;
$this->params['slug'] = $this->slug;
/**
* Code in Helper file
*/
function get_blog_posts($params, $category_rewrite)
{
$CI = &get_instance();
/**
* Count and get all the posts
*/
$posts_count = $CI->blog->getPosts($params, TRUE);
$posts = $CI->blog->getPosts($params);
/**
* Pagination
*/
$config['base_url'] = $category_rewrite['slug'] . 'page/';
$config['total_rows'] = (int)$posts_count;
$config['per_page'] = isset($params['limit']) ? (int)$params['limit'] : FALSE;
$config['uri_segment'] = 5;
$config['num_links'] = 10;
$config['use_page_numbers'] = TRUE;
$config['suffix'] = $CI->uri->getpath() ? '/?' . $CI->uri->getpath() : '';
$config['first_url'] = $category_rewrite['slug'];
$CI->pagination->initialize($config);
$pagination = $CI->pagination->create_links();
/**
* Code in model file
*/
public function getPosts($params, $count = FALSE)
{
$params = array_merge($this->params, $params);
extract($params);
$this->db->join('blog_posts_langs as bpl', 'bp.id = bpl.post_id', 'left');
$this->db->join('blog_categories as bc', 'bc.id = bp.category_id', 'left');
$this->db->join('blog_categories_multi as bcm', 'bcm.post_id = bp.id', 'left');
$this->db->join('url_rewrite as urwr', 'urwr.url_type = "blog_post" AND urwr.element_id = bp.id AND urwr.lang_id = '. $lang_id, 'left');
if ($category) {
$this->db->where('(bc.id = "' . $category . '" OR bc.parent_id IN (' . $in_categories . ') OR bcm.category_id = '. $category .' )');
}
收到一只叮咚
偶然的你