xiaocms进阶教程:修改上一篇下一篇显示相关栏目而非所有新闻

观察xiaocms源码会发现上一篇下一篇的内容会在core/controller/index.php中。进入indexAction方法中。由于上一篇下一篇是在新闻阅读中才会出现,所以直接进入 id这个else中。

    else if ($this->get('id')){
        $id    = (int)$this->get('id');
        $content  = $this->db->setTableName('content')->find($id);
        if (empty($content)) {
            header('HTTP/1.1 404 Not Found');
            $this->show_message('不存在此内容!');
        }
        if (empty($content['status'])) $this->show_message('此内容正在审核中不能查看!');
        $category   = $this->category_cache[$content['catid']];
        if($category['islook'] && !$this->member_info) $this->show_message('当前栏目游客不允许查看');
        $content_add = $this->db->setTableName($category['tablename'])->find($id);
        $content_add = $this->handle_fields($this->content_model[$content['modelid']]['fields'], $content_add);
        $content  = $content_add ? array_merge($content,$content_add) : $content;
        $content['page']   = (int)$this->get('page') ? (int)$this->get('page') : 1;
        if (strpos($content_add['content'], '[XiaoCms-page]') !== false) {
            $pdata  = array_filter ( explode('[XiaoCms-page]', $content_add['content']) );
            $pagenumber = count($pdata);
            $content['content'] = $pdata[$content['page']-1];
            $pageurl = $this->view->get_show_url($content, 1);
            $pagelist = xiaocms::load_class('pager');
            $pagelist = $pagelist->total($pagenumber)->url($pageurl)->num(1)->hide()->page($content['page'])->output();
            $this->view->assign('pagelist', $pagelist);
        }

        $content['cat'] = $category;
        //$prev_page = $this->db->setTableName('content')->order('id DESC')->getOne(array('iddb->setTableName('content')->order('id DESC')->getOne(array('idview->get_show_url($prev_page);
        //$next_page = $this->db->setTableName('content')->order('id ASC')->getOne(array('id>?', 'modelid=' .$content['modelid'] , 'status!=0'), $id);
        $next_page = $this->db->setTableName('content')->order('id ASC')->getOne(array('id>?', 'catid=' .$content['catid'] , 'status!=0'), $id);
        if ($next_page) $next_page['url'] =  $this->view->get_show_url($next_page);
        $this->view->assign($content);
        $this->view->assign($this->showSeo($content, $content['page']));
        $this->view->assign(array(
            'prev_page' => $prev_page,
            'next_page' => $next_page,
        ));
        $this->view->display($category['showtpl']);
    }

重点查看被注释掉的两句话,可以看出作者是按照modelid来检索数据的,那么在这里我们将modelid替换成catid不就是只能检索当前栏目了吗?

你可能感兴趣的:(xiaocms进阶教程:修改上一篇下一篇显示相关栏目而非所有新闻)