Z-Blog是由RainbowSoft Studio開發的一款小巧而強大的基于Asp/php平臺的Blog程序了,下文介紹的是php版本的ZBLOG調用隨機文章、熱門文章、熱評文章代碼.
使用方法:
第一、在我們的主題目錄中需要創建include.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(!emptyempty($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()'=>' ');
- } //開源軟件:Vevb.com
- }
- $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;
- }
然后就是在我們需要的界面模板中調用.
熱門文章,代碼如下:
- {$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>
調用10篇熱門文章,熱評文章,代碼如下:
- {$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>
直接用zblogphp的原生代碼,代碼如下:
- <img src="{php}$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
- $content = $article->Content;
- preg_match_all($pattern,$content,$matchContent);
- echo $matchContent[1][0];
- {/php}" />
這些代碼前臺編譯出來的html代碼就是:<img src="圖片地址">,可以加在任意想調用的地方.
PHP版隨機文章的調用方法:
不會寫插件,直接爆方法.
1、打開zb_system\function\c_system_event.php
在743行,$zbp->AddBuildModule('previous');后面添加$zbp->AddBuildModule('sjarticles');
在781行,$zbp->AddBuildModule('previous');后面添加$zbp->AddBuildModule('sjarticles');
在最后后面添加如下代碼:
- function BuildModule_sjarticles(){
- global $zbp;
- $articles=$zbp->GetArticleList(
- array('*'),
- array(array('=','log_Type',0),array('=','log_Status',0)),
- array('rand()'=>' '),
- array(10),
- null
- );
- $s='';
- foreach ($articles as $article) {
- $s .='' . $article->Title . '';
- }
- return $s;
- }
2、打開zb_system\function\lib\zblogphp.php
在218行,$this->RegBuildModule('previous','BuildModule_previous');后面添加$this->RegBuildModule('hotarticles','BuildModule_sjarticles');
3、打開數據庫,在zbp_module表,添加新數據,15,熱門文章,sjarticles,,0,divsjarticles,ul,0,system,0
調用方法:在相應地方調用{$modules['sjarticles'].Content}
新聞熱點
疑難解答