当前位置:首页 > 未命名

zblog使用GetList调用最新发布文章并过滤某个分类

8976988823个月前 (01-10)未命名5

最近有一个调用网站最新12篇文章并过滤某个分类下的文章的需求。

首先想到的自然是在foreach里过滤掉某个分类的文章:

$arry=GetList(12);    foreach ($arry as $related) {        if($related->Category->ID!=7){    echo '<a href="'.$related->Url.'">'.$related->Title.'</a>';    }}

但是这种操作会使输出的文章数量会少掉了过滤的数量。

看以看到,上面的操作中用了GetList(12)来调用最新的12篇文章。

GetList()是ZBLOG开发中常用的一个函数,可以实现各种条件的文章调用。

ZBLOG官方在ZBP1.7后对GetList()进行了优化升级,支持了更多查询条件。

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)

调用最新发布文章并过滤某个分类自是不在话下。

直接贴出代码:

$arry=GetList(array('count'=>12,'where_custom' => array(array('<>', 'log_CateID', 1))));foreach ($arry as $related) {    echo '<a href="'.$related->Url.'">'.$related->Title.'</a>';}

注:12是调用文章的数量,1是要过滤的分类ID。


扫描二维码推送至手机访问。

版权声明:本文由米表程序发布,如需转载请注明出处。

本文链接:https://www.9909999.xyz/post/633.html

分享给朋友: