zblogphp使用GetArticleList、GetList函数调用热门文章列表
投稿:yin
一般我们调用ZBLOG PHP文章的时候会用到最新文章、点击数、评论数文章调用,同时我们还可能 会在一些特定的位置调用本周、本月、本年度的热门文章。
热门文章
目录文件:zb_system/function/lib/zblogphp.php
zbp全局操作类ZBlogPHP中有很多数据表操作的默认函数:GetArticleList()、GetPageList()、GetCommentList()、GetMemberList()、GetTagList()、GetCategoryList()、GetModuleList()、GetUploadList()这8个获取列表的函数正好对应8个默认数据表。当前还有很多其他函数可以调用
ZBlogphp默认的调用点击率最高的文章(30天内),是全站文章不分时间段、不能按分类调用。
直接在当前使用的主题模板页面添加如下代码:
{php}    
$stime = time();
$ytime = 30*24*60*60;
$ztime = $stime-$ytime;
$order = array('log_ViewNums'=>'DESC');
$where = array(array('=','log_Status','0'),array('>','log_PostTime',$ztime));
$array = $zbp->GetArticleList(array('*'),$where,$order,array(10),'');
{/php}
{foreach $array as $cmslist}
<li><a href="{$cmslist.Url}" title="{$cmslist.Title}">{$cmslist.Title}</a></li>
{/foreach}调用include方法
在主题include.php文件中加入下面功能函数:
function article_hot(){
    global $zbp,$str;
    $str = '';
    $stime = time();
	$ytime = 30*24*60*60;
	$ztime = $stime-$ytime;
	$order = array('log_ViewNums'=>'DESC');
	$where = array(array('=','log_Status','0'),array('>','log_PostTime',$ztime));
	$array = $zbp->GetArticleList(array('*'),$where,$order,array(10),'');
    foreach ($array as $tag) {
        $str .= "<a href=\"{$tag->Url}\" title=\"{$tag->Name}\">{$tag->Name}</a>";
    }
    return $str;
}当前使用的主题模板页面中自行调用
{php}echo article_hot();{/php}新版zblogphp GetList函数
在Zblog php 1.7版本以前使用GetList函数是无法调用热门、热评或随机文章列表的,调用自定义排序列表通常会使用GetArticleList函数,但在zblog php 1.7版本更新之后,GetList函数增加了where_custom、order_custom等多个重要参数,从而可以轻易地调用热门文章、热评文章或随机文章等列表了。
分类ID:可以分类别调用了
目录文件:zb_system/function/c_system_function.php
GetList($count = 10, $cate = null, $auth = null, $date = null, $tags = null, $search = null, $option = null)
* @param int $count 数量 (1.7支持复杂的array参数,$count为array时后面的参数可以不设)
* @param null $cate 分类ID
* @param null $auth 用户ID
* @param null $date 日期
* @param null $tags 标签
* @param null $search 搜索关键词
* @param null $option
示例热门文章
    $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>';参数示例
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
)到此这篇关于zblogphp使用GetArticleList、GetList函数调用热门文章列表的文章就介绍到这了,更多相关zblogphp调用热门文章列表内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
