首页 / 值得一看 / zblog教程 / 正文

zblogphp使用GetArticleList、GetList函数调用热门文章列表

2023-07-05zblog教程阅读 222

一般我们调用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函数调用热门文章列表的文章就介绍到这了.

信息由用户投稿以及用户自行发布,真实性、合法性由发布人负责,涉及到汇款等个人财产或隐私内容时请仔细甄别,注意防骗!如有侵权,请联系:wwwlaoyuwang#126.com(#=@)!我们会第一时间核实处理!

相关推荐

  • 虚拟主机中zblog如何强制全站https

    网站改版升级了https安全访问,可之前搜索引擎收录的全部都是http的链接,如果不做301重定向,别人访问时,进入的依旧不是安全链接。如何把zblogPHP全站http301重定向到https的域名...

    92zblog教程2023-10-01
  • zblogphp使用GetArticleList、GetList函数调用热门文章列表

    一般我们调用ZBLOGPHP文章的时候会用到最新文章、点击数、评论数文章调用,同时我们还可能会在一些特定的位置调用本周、本月、本年度的热门文章。热门文章目录文件:zb_system/funct...

    222zblog教程2023-07-05
  • zblog修改列表分页条首页/上页/下页/末尾符号为文字

    Z-Blog使用{template:pagebar}调用的翻页条是用‹‹、‹、›、››符号分别表示首页、上一篇、下一页和最后一页,如果不想用符号直接显示中文怎么办?可以尝试使用翻页条源代码来修改或者通...

    207zblog教程2023-06-12
  • zblog搜索页面制作教程

    搜索功能是一个网站中必不可少的功能,同样在zblog模板中也支持搜索页面的制作,而zblog中的搜索页面是要用一个单独模板来制作的,下面来进行一下讲解本文讲解是以zblog新版本为例来演示的。首先,先...

    252zblog教程2023-06-11
  • ZblogPHP调用某个分类的随机文章

    随机文章是非常常见的内容模块,有利于提高网站整体的收录。区别于常见的CMS,我发现Zblog并没有表情直接调用随机文章,那么,我们要实现调用某个分类的随机文章,应该怎么实现呢?随机文章从网上看到的随机...

    377zblog教程2023-05-10