控制器/ home.php
$this->page_model->counter($this->data['post_detail']->post_ID);
$this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
$this->data['gallery_list'] = $this->post_model->post($this->data['post_detail']->post_ID, true);
$isAjax = array('news-post');
if (in_array($this->data['post_detail']->template_name, $isAjax))
{
if ( ! $this->input->is_ajax_request())
redirect($this->data['page_detail']->post_alias);
return $this->load->view($this->data['post_detail']->template_name, $this->data);
}
$this->load->view($this->data['post_detail']->template_name, $this->data);
视图/ news.php
<?php
$this->load->library('pagination');
$config['base_url'] = 'http://gsa-constructionspecialist.com/articles/article';
$config['total_rows'] = 14;
$config['per_page'] = 5;
$this->pagination->initialize($config);
?>
<div class="w626 content right">
<?php
if ($post_list){
foreach ($post_list as $pl){
?>
<div>
<p><br><br><strong><?php echo $pl->post_title; ?></strong></p>
<p><?php echo date('F jS, Y',strtotime($pl->post_date)); ?></p>
<br/>
<div style="text-align:justify"><?php echo word_limiter(strip_tags($pl->post_content),25); ?><a href="<?php echo site_url('articles/'.$this->uri->segment(2).'/detail/'.$pl->post_alias); ?>"><span style="color:#fff"> Read More ></span></a></div>
</div>
<?php } } ?>
<?php echo $this->pagination->create_links(); ?>
我正在尝试设置分页,但它只显示在底部,并且它不会隐藏假设在下一页上的文章。
请帮忙修改代码?提前谢谢。
答案 0 :(得分:0)
分页类将根据您提供给它的信息生成页码,但是由您来生成特定页面的实际结果。您可以告诉分页课每页5个结果,但实际上它并不知道您是否每页输出5个结果或500个。
在我看来好像:
$this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
需要传入的当前页码,即
$this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID, $current_page);
然后,您需要使用LIMIT修改模型中的数据库查询,以限制该页面的结果数(和偏移量)。
这有帮助吗?