局限于函数参数,在zblog php 1.7版本以前使用GetList函数是无法调用热门、热评或随机文章列表的,调用自定义排序列表通常会使用GetArticleList函数,但在zblog php 1.7版本更新之后,GetList函数增加了where_custom、order_custom等多个重要参数,从而可以轻易地调用热门文章、热评文章或随机文章等列表了。
1.7新版本GetList函数:
语法
1 | $result = GetList(array('count'=>10)) //返回array(Post类型) 或是 空array() |
参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | array(
'count' => 10, //(可省略)
'cate' => 1, //(可省略)
'auth' => 2, //(可省略)
'date' => '2020-1', //(可省略)
'tags' => 'abc', //(可省略)
'search' => 's', //(可省略)
//以下是原$option参数的key键
'post_type' => null, //指定查询Post表的类型 (可省略)
'post_status' => null, //指定查询Post表的状态 (可省略)
'only_ontop' => false, //指定全是置顶 (可省略)
'only_not_ontop' => false, //指定全不是置顶 (可省略)
'has_subcate' => false, //指定包含子孙目录 (可省略)
'is_related' => false, //指定查询相关文章 (可省略)
'order_by_metas' => false, //指定按Metas值排序输出结果 (可省略)
'random' => 5, //指定抽取5篇Post表的记录 (可省略)
'where_custom' => array(array('=', 'log_Template', '')), //自定义where
'order_custom' => array('log_ViewNums' => 'DESC',
'log_CommNums' => 'ASC'), //自定义order
) |
示例:
热门文章
1 2 3 4 5 6 7 8 9 10 11 12 13 | $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>'; |
热评文章
1 2 3 4 5 6 7 8 9 10 11 12 13 | $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>'; |
随机文章
1 2 3 4 5 6 7 8 9 10 11 12 | $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>'; |