zblog使用GetList函数调用热门/热评/随机文章列表
局限于函数参数,在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()
参数
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)
示例:
热门文章
$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>';
信息由用户投稿以及用户自行发布,真实性、合法性由发布人负责,涉及到汇款等个人财产或隐私内容时请仔细甄别,注意防骗!如有侵权,请联系:wwwlaoyuwang#126.com(#=@)!我们会第一时间核实处理!