我的Category Wise帖子分页在codeigniter中不起作用。 假设我在“行为”类别中有5个帖子,那么我希望每页显示2个帖子,当我单击第二个分页,然后将其重定向到第一个分页记录时,仅显示2个帖子,而不会显示第3个和第4个记录。
public function listing($id = null) {
$categoryid = base64_decode($id);
/* Pagination Code */
$config["base_url"] = base_url().
"categories/listing/".base64_encode($categoryid);
$config["total_rows"] = count($this - > categories_model - > recordcount(['post_category_id' => $categoryid, 'post_del_status' => 0, 'post_status' => 0]));
//print_r( $config["total_rows"] );
//exit();
$config["per_page"] = 2;
$choice = $config["total_rows"] / $config["per_page"];
$config["uri_segment"] = 3;
$config["num_links"] = round($choice);
$config['full_tag_open'] = ' <div class="navigation pagination"><div class="nav-links">';
$config['full_tag_close'] = '</div></div>';
$config['num_tag_open'] = '<span class="page-numbers">';
$config['num_tag_close'] = '</span>';
$config['cur_tag_open'] = '<span class="page-numbers current">';
$config['cur_tag_close'] = '</span>';
$config['prev_tag_open'] = '<span class="page-numbers">';
$config['prev_tag_close'] = '</span>';
$config['next_tag_open'] = '<span class="page-numbers">';
$config['next_tag_close'] = '</span>';
$config['first_link'] = 'First Page';
$config['first_tag_open'] = '<span class="page-numbers">';
$config['first_tag_close'] = '</span>';
$config['last_link'] = 'Last Page';
$config['last_tag_open'] = '<span class="page-numbers">';
$config['last_tag_close'] = '</span>';
$this - > pagination - > initialize($config);
$page = ($this - > uri - > segment(3)) ? $this - > uri - > segment(3) : 0;
/* Common sections */
$data['topfooter'] = $this - > home_model - > get_topfooter();
$data['socialmedia'] = $this - > home_model - > get_socialmedia();
$data['metadata'] = $this - > home_model - > get_metadata();
$data['logo_banner'] = $this - > home_model - > get_logo();
/* common sections */
$data['categoryposts'] = $this - > categories_model - > get_categoryposts(['td_allpost.post_del_status' => 0, 'td_allpost.post_status' => 0, 'td_category_subcategory.category_status' => 0, 'td_category_subcategory.category_del_status' => 0, 'post_category_id' => $categoryid], $config["per_page"], $page);
$data["links"] = $this - > pagination - > create_links();
//print_r($data['categoryposts']);
//exit();
$this - > load - > view('frontend/front_header_view', $data);
$this - > load - > view('frontend/front_category_view', $data);
$this - > load - > view('frontend/front_footer_view', $data);
}
public function get_categoryposts($data, $limit, $start) {
$this - > db - > select('*, COUNT(td_comments.comment_post_id) as totalcomment');
$this - > db - > join('td_comments', 'td_allpost.post_id=td_comments.comment_post_id', 'left outer');
$this - > db - > join('td_category_subcategory', 'td_allpost.post_category_id=td_category_subcategory.category_id', 'left outer');
$this - > db - > join('td_post_imagevideo', 'td_allpost.post_id=td_post_imagevideo.post_imagevideo_id', 'left outer');
$this - > db - > limit($limit, $start);
$this - > db - > group_by('td_allpost.post_id');
$this - > db - > order_by('td_allpost.post_priority', 'DESC');
$query = $this - > db - > get_where("td_allpost", $data);
return $query - > result_array();
}
public function get_categoryposts($data, $limit, $start) {
$this - > db - > select('*, COUNT(td_comments.comment_post_id) as totalcomment');
$this - > db - > join('td_comments', 'td_allpost.post_id=td_comments.comment_post_id', 'left outer');
$this - > db - > join('td_category_subcategory', 'td_allpost.post_category_id=td_category_subcategory.category_id', 'left outer');
$this - > db - > join('td_post_imagevideo', 'td_allpost.post_id=td_post_imagevideo.post_imagevideo_id', 'left outer');
$this - > db - > limit($limit, $start);
$this - > db - > group_by('td_allpost.post_id');
$this - > db - > order_by('td_allpost.post_priority', 'DESC');
$query = $this - > db - > get_where("td_allpost", $data);
return $query - > result_array();
}
答案 0 :(得分:1)
Change your uri segment value from this->uri->segment(3) to
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0