热门文章、随机文章或热评文章是网站最常见的三大模块,在进行网页制作的时候会经常调用到,Z-Blog php版本程序的三大模块调用方法,可以通过创建include.php文件,添加函数代码后,使用GetLis一样的方法进行调用。
如果主题存在include.php文件,直接在文件中添加以下代码;如果不存在include.php文件,则先创建该文件,并在主题信息文件theme.xml中的标签引用该文件,然后添加以下代码:<?php /**
*获取文章列表
*@paramint$count数量
*@paramnull$cate分类ID
*@paramnull$auth用户ID
*@paramnull$date日期
*@paramnull$tags标签
*@paramnull$search搜索关键词
*@paramnull$order排序
*@paramnull$option
*@returnarray|mixed
*/functionTcgetList($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)
returnarray();
$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=newCategory;
$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]->SubCategorysas$subcate){
$arysubcate[]=array('log_CateID',$subcate->ID);
}
$w[]=array('array',$arysubcate);
}
}
}
if(!is_null($auth)){
$author=newMember;
$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('+1month',$datetime));
}
}
if(!is_null($tags)){
$tag=newTag;
if(is_array($tags)){
$ta=array();
foreach($tagsas$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($articlesas$k=>$a){
if($a->ID==$option['is_related'])
unset($articles[$k]);
}
if(count($articles)==$count){
array_pop($articles);
}
}
return$articles;}?>
函数调用代码:方法和官方给出的GetList一样,区别是比GetList多了一个参数条件
热门文章
{$array=TcgetList(10,null,null,null,null,null,null,'hot');}
{foreach$arrayas$related}
{$related.Time('m-d')}{$related.Title}
{/foreach}
随机文章{$array=TcgetList(10,null,null,null,null,null,null,'rand');}
{foreach$arrayas$related}{$related.Time('m-d')}{$related.Title}
{/foreach}
热评文章
{$array=TcgetList(10,null,null,null,null,null,null,'comm';}
{foreach$arrayas$related}{$related.Time('m-d')}{$related.Title}
{/foreach}