在zblog中,现有的模块中有自带的最新发布文章列表,但是热门文章列表、随机文章列表、热点评论文章列表等都没有。下面小编就来给大家介绍下如何去增加这些文章列表。
首先,我们要找到该主题模板下的include.php文件,然后在里面加入这样的一段代码:
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; }
记住function 后面的单词,这里在模板中需要使用到,这里用的是TcgetList,那么在对应模板文件中要调用相关文章列表就需要使用到这个字母。比如说热门文章列表:
{$array = TcgetList(10,null,null,null,null,null,null,'hot');} <ul> {foreach $array as $related} <li><a href="{$related.Url}" title="{$related.Title}" target="_blank">{$related.Title}</li> {/foreach} </ul>
随机文章列表:
{$array = TcgetList(10,null,null,null,null,null,null,'rand');} <ul> {foreach $array as $related} <li><a href="{$related.Url}" title="{$related.Title}" target="_blank">{$related.Title}</li> {/foreach} </ul>
从这两端代码对比中我们发现,热门文章与随机文章的调用代码基本上一样,只有第一行代码最后一个单词不一样,热门文章是hot,随机文章是rand。而最新文章与热评文章的参数分别为new与comm,所以调用最新文章及热评文章只需要对应更改单词即可。
下一篇: Windows10下如何注册32位OCX控件
上一篇:为什么做SEO常常达不到预期的效果?
评论