当前位置:-go»- 网站首页 / 軟件应用區 / 正文

Zblog程序使用GetArticleList、GetList调用热门文章列表

6个月前 (11-03) / 116 次围观 / 0 次吐槽

一般我们调用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
)


调用指分类抱括子分类的热门文章案列:

{php}
$result = GetList(
	array(
	     'cate' => 1,
		'count'=>5,
		'post_type'=>'post',
		'has_subcate'=>true,			
		'order_custom' => array('log_ViewNums' => 'DESC')
	));
{/php}

{foreach $result as $related}	
	<div class="post"><figure class="post-thumb"><a href="{$related.Url}" title="{$related.Title}"><img src="{if $related.Metas.thumburl}{$related.Metas.thumburl}{elseif $related.AllImages}{$related.Thumbs(370, 231, 1, true)[0]}{else}{$host}zb_users/theme/{$theme}/style/picture/wutu.jpg{/if}" alt="{$related.Title}"></a></figure><h5><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></h5>
	</div>
{/foreach}


上面就是关于zblogphp使用GetArticleList、GetList函数调用热门文章列表的文章,本文摘自:laoyublog.com/jiaocheng/3447.html


更新: 2023-11-10

相關 博客程序

本筆記站部分文章、圖片收集於 互聯網,作者:僅作自學筆記;請勿轉載用於 非法途逕 , 轉載注明 _ 我欣飞祥
Url : 【 http://uuucd.cn/software/1950.html
额~ 本文暂时没人评论 来添加一个吧 …

发表评论

必填

选填

选填

必填

◎请提交您的留言_感谢您的参与讨论!!

ipcooc2@gmail.com