国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Z-Blog > 正文

zblog PHP中調用熱門文章、隨機文章和熱評文章代碼

2024-09-06 23:00:55
字體:
來源:轉載
供稿:網友

熱門文章、隨機文章或熱評文章是網站最常見的三大模塊,在進行網頁制作的時候會經常調用到,Z-Blog php版本程序的三大模塊調用方法,可以通過創建include.php文件,添加函數代碼后,使用GetLis一樣的方法進行調用。

如果主題存在include.php文件,直接在文件中添加以下代碼;如果不存在include.php文件,則先創建該文件,并在主題信息文件theme.xml中的標簽引用該文件,然后添加以下代碼:

<?php/** * 獲取文章列表 * @param int $count 數量 * @param null $cate 分類ID * @param null $auth 用戶ID * @param null $date 日期 * @param null $tags 標簽 * @param null $search 搜索關鍵詞 * @param null $order 排序 * @param null $option * @return array|mixed */function TcgetList($count = 10, $cate = null, $auth = null, $date = null, $tags = null, $search = null, $option = null,$order=null) {    global $zbp;    if (!is_array($option)) {        $option = array();    }    if (!isset($option['only_ontop']))        $option['only_ontop'] = false;    if (!isset($option['only_not_ontop']))        $option['only_not_ontop'] = false;    if (!isset($option['has_subcate']))        $option['has_subcate'] = false;    if (!isset($option['is_related']))        $option['is_related'] = false;    if ($option['is_related']) {        $at = $zbp->GetPostByID($option['is_related']);        $tags = $at->Tags;        if (!$tags)            return array();        $count = $count + 1;    }    if ($option['only_ontop'] == true) {        $w[] = array('=', 'log_IsTop', 0);    } elseif ($option['only_not_ontop'] == true) {        $w[] = array('=', 'log_IsTop', 1);    }    $w = array();    $w[] = array('=', 'log_Status', 0);    $articles = array();    if (!is_null($cate)) {        $category = new Category;        $category = $zbp->GetCategoryByID($cate);        if ($category->ID > 0) {            if (!$option['has_subcate']) {                $w[] = array('=', 'log_CateID', $category->ID);            } else {                $arysubcate = array();                $arysubcate[] = array('log_CateID', $category->ID);                foreach ($zbp->categorys[$category->ID]->SubCategorys as $subcate) {                    $arysubcate[] = array('log_CateID', $subcate->ID);                }                $w[] = array('array', $arysubcate);            }        }    }    if (!is_null($auth)) {        $author = new Member;        $author = $zbp->GetMemberByID($auth);         if ($author->ID > 0) {            $w[] = array('=', 'log_AuthorID', $author->ID);        }    }    if (!is_null($date)) {        $datetime = strtotime($date);        if ($datetime) {            $datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']);            $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime));        }    }    if (!is_null($tags)) {        $tag = new Tag;        if (is_array($tags)) {            $ta = array();            foreach ($tags as $t) {                $ta[] = array('log_Tag', '%{' . $t->ID . '}%');            }            $w[] = array('array_like', $ta);            unset($ta);        } else {            if (is_int($tags)) {                $tag = $zbp->GetTagByID($tags);            } else {                $tag = $zbp->GetTagByAliasOrName($tags);            }            if ($tag->ID > 0) {                $w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%');            }        }    }    if (is_string($search)) {        $search=trim($search);        if ($search!=='') {            $w[] = array('search', 'log_Content', 'log_Intro', 'log_Title', $search);        }    }        if(!empty($order)){    if($order=='new'){        $order = array('log_PostTime'=>'DESC');    }    if($order=='hot'){        $order = array('log_ViewNums'=>'DESC');    }    if($order=='comm'){        $order = array('log_CommNums'=>'DESC');    }    if($order=='rand'){        $order = array('rand()'=>' ');    }    }    $articles = $zbp->GetArticleList('*', $w, $order, $count, null, false);    if ($option['is_related']) {        foreach ($articles as $k => $a) {            if ($a->ID == $option['is_related'])                unset($articles[$k]);        }        if (count($articles) == $count){            array_pop($articles);        }    }    return $articles;}?>

函數調用代碼:方法和官方給出的GetList一樣,區別是比GetList多了一個參數條件

zblogphp調用熱門文章的代碼:

{$array = TcgetList(10,null,null,null,null,null,null,'hot');}<ul id="related">{foreach $array as $related}    <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li>{/foreach}</ul>

zblogphp調用隨機文章的代碼:

{$array = TcgetList(10,null,null,null,null,null,null,'rand');}<ul id="related">{foreach $array as $related}    <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li>{/foreach}</ul>

zblogphp熱評文章的代碼:

{$array = TcgetList(10,null,null,null,null,null,null,'comm');}<ul id="related">{foreach $array as $related}    <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li>{/foreach}</ul>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张家港市| 彩票| 辉县市| 明水县| 名山县| 姚安县| 克什克腾旗| 密山市| 澳门| 绥中县| 曲阳县| 德惠市| 玉树县| 永修县| 博兴县| 宝清县| 双江| 瑞金市| 萝北县| 鲁甸县| 平定县| 额敏县| 南涧| 榕江县| 繁昌县| 万盛区| 伽师县| 泾川县| 连州市| 治多县| 永新县| 炎陵县| 汽车| 壶关县| 冀州市| 临沂市| 黄龙县| 平乡县| 松桃| 岗巴县| 东兰县|