Home  >  Article  >  php教程  >  tipask问题添加热门问答模块

tipask问题添加热门问答模块

WBOY
WBOYOriginal
2016-05-25 16:48:071150browse

tipask这款系统中虽然功能比较强大但是对于我来讲少了一个热门问题模块了,下面我就整理了一个站长的开发例子与各位分享。

有个网站是用tipask来搭建的问答系统,今天客户要求添加热门问题模块,之前都是用tipask的原生模块,比如说推荐问答、未解决问答等,看来只能自己二次开发了,上网找了下关于tipask的二次开发还真是少……于是简单翻了下tipask的代码,用我的方式增加了热门问题模块。

tipask的主要函数都在model文件夹下,找到系统核心文件base.class.php,里面有这样一个函数fromcache,用于生成函数下各种模块,例如悬赏问题、精彩推荐等,我们要做的就是在这里按照前后代码加上一条我们需要的热门问题模块。

例如在代码

case 'notelist'://首页右侧公告列表

前加上我们的模块代码:

case 'hotlist'://热门问题
$this->load('hot');//www.phprm.com
$cachedata = $_ENV['hot']->get_list();
break;

这里我是仿照recommend推荐模块,又新建的一个hot.class.php用于上面代码的调用,其实完全可以仿照上面的调用question.class.php文件里的list_by_condition函数,但是通过到question.class.php文件下查看list_by_condition函数只能够加入sql的where判断,而我需要的热门模块只需要改动一下order by,所以我只能新建一个hot.class.php文件自己写数据库调用了。

hot.class.php文件如下:

<?php
$this->base = $base;
$this->db = $base->db;
function get_list($start = 0, $limit = 7) {
    $hotlist = array();
    $query = $this->db->query("SELECT * FROM " . DB_TABLEPRE . "question ORDER BY views DESC LIMIT $start,$limit");
    while ($hot = $this->db->fetch_array($query)) {
        $hot[&#39;category_name&#39;] = $this->base->category[$hot[&#39;cid&#39;]][&#39;name&#39;];
        $hot[&#39;format_time&#39;] = tdate($hot[&#39;time&#39;]);
        $hot[&#39;category_name&#39;] = $this->base->category[$hot[&#39;cid&#39;]][&#39;name&#39;];
        $hot[&#39;url&#39;] = url(&#39;question/view/&#39; . $hot[&#39;qid&#39;], $hot[&#39;url&#39;]);
        $hot[&#39;image&#39;] = $hot[&#39;image&#39;] ? $hot[&#39;image&#39;] : &#39;css/default/recomend.jpg&#39;;
        $hotlist[] = $hot;
    }
    return $hotlist;
}
?>

好了,tipask关于新建模块的二次开发就结束了,只要仿照这来就行了

 


本文链接:

收藏随意^^请保留教程地址.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn