在zblog php 1.7版本以前,使用GetList函数无法调用热门、热评或随机文章列表,通常会使用GetArticleList函数来调用自定义排序列表。然而,在zblog php 1.7版本更新之后,GetList函数增加了where_custom、order_custom等多个重要参数,从而可以轻松地调用热门文章、热评文章或随机文章等列表了。
1.7新版本的GetList函数语法如下所示:
$result = GetList(array('count'=>10)); //返回array(Post类型) 或是 空array()
其中,参数包括:
count: 返回的文章数量,可省略; cate:文章所属分类,可省略; auth:作者ID,可省略; date:发表日期,可省略; tags:文章标签,可省略; search:搜索关键字,可省略; post_type:指定查询Post表的类型,可省略; post_status:指定查询Post表的状态,可省略; only_ontop:指定查询全是置顶文章,可省略; only_not_ontop:指定查询全不是置顶文章,可省略; has_subcate:指定查询包含子孙目录的文章,可省略; is_related:指定查询相关文章,可省略; order_by_metas:指定按Metas值排序输出结果,可省略; random:指定抽取多少篇Post表的记录,可省略; where_custom:自定义where条件; order_custom:自定义order排序。
以下是GetList函数的示例:
热门文章:
$result = GetList(
array(
'count'=>10,
'post_type'=>'post',
'has_subcate'=>true,
'order_custom' => array('log_ViewNums' => 'DESC')
)
);
$list = '<ul>';
foreach ($result as $item) {
$list .= '<li><a href="'.$item->Url.'" title="'.$item->Title.'">'.$item->Title.'</a ></li>';
}
$list .= '</ul>';热评文章:
$result = GetList(
array(
'count'=>10,
'post_type'=>'post',
'has_subcate'=>true,
'order_custom' => array('log_CommNums' => 'DESC')
)
);
$list = '<ul>';
foreach ($result as $item) {
$list .= '<li><a href="'.$item->Url.'" title="'.$item->Title.'">'.$item->Title.'</a ></li>';
}
$list .= '</ul>';随机文章:
$result = GetList(
array(
'post_type'=>'post',
'has_subcate'=>true,
'random' => 10
)
);
$list = '<ul>';
foreach ($result as $item) {
$list .= '<li><a href="'.$item->Url.'" title="'.$item->Title.'">'.$item->Title.'</a ></li>';
}
$list .= '</ul>';希望这篇文章更加清晰明了,能够帮助读者更好地理解GetList函数的使用方法。








