调用随机文章、热门文章、热评文章脚本方法

调用随机文章、热门文章、热评文章脚本方法,第1张

在自定义ZBLOG PHP模板的过程中,可能需要使用调用随机文章热门文章等解决方案。在这里,看到@唐同学的博客里有这样的剧本。这里我也转载一下。下次用的时候测试一下实用性。如果有问题,我会更新的。

用法:

首先,我们需要在我们的主题目录中创建一个include.php文件,如果有,直接添加一个脚本。

/**
*获取文章列表
* @ param int $ count quantity
* @ param null $ cate类别ID
* @param null $auth用户ID
* @param null $date日期
* @param null $tags标签
* @param null $search关键字
* @ param null $ order sort
* @ param null $ option
* @ param null $ option

如果(!is _ array($ option)){
$ option = array();
}

如果(!isset($ option[ # 39;only _ ontop # 39]))
$ option[ # 39;only _ ontop # 39] =假;
如果(!isset($ option[ # 39;only _ not _ ontop # 39]))
$ option[ # 39;only _ not _ ontop # 39] =假;
如果(!isset($ option[ # 39;has _ subcate # 39]))
$ option[ # 39;has _ subcate # 39] =假;
如果(!isset($ option[ # 39;is _ related # 39]))
$ option[ # 39;is _ related # 39] =假;

if($ option[ # 39;is _ related # 39]){
$ at = $ zbp- gt;GetPostByID($option[ # 39;is _ related # 39]);
$ tags = $ at- gt;标签;
如果(!$ tags)
return array();
$ count = $ count+1;
}

if($ option[ # 39;only _ ontop # 39]= = true){
$ w[]= array( # 39;=#39;, #39;log _ IsTop # 39, 0);
} else if($ option[ # 39;only _ not _ ontop # 39]= = true){
$ w[]= array( # 39;=#39;, #39;log _ IsTop # 39, 1);
}

$ w = array();
$ w[]= array( # 39;=#39;, #39;log _ Status # 39, 0);

$ articles = array();

如果(!is _ null($ cate)){
$ Category =新类别;
$ category = $ zbp- gt;GetCategoryByID($ cate);

if($category- gt;ID gt0) {

如果(!$ option[ # 39;has _ subcate # 39]){
$ w[]= array( # 39;=#39;, #39;log _ CateID # 39,$ category- gt;ID);
} else {
$ arysucate = array();
$ ary subcat[]= array( # 39;log _ CateID # 39,$ category- gt;ID);
foreach($ zbp- gt;类别[$ category- gt;ID]- gt;subcategory as $ sub cat){
$ ary sub cat[]= array( # 39;log _ CateID # 39,$ sub cat- gt;ID);
}
$ w[]= array( # 39;数组 # 39;,$ ary sub cate);

}

}
}

如果(!is_null($auth)) {
$author =新成员;
$ author = $ zbp- gt;GetMemberByID($ auth);

if($ author- gt;ID gt0){
$ w[]= array( # 39;=#39;, #39;log _ AuthorID # 39,$ author- gt;ID);
}
}

如果(!is _ null($ date)){
$ datetime = strtotime($ date);
if($ datetime){
$ date title = str _ replace(array( # 39;% y % # 39, #39;% m % # 39),数组(日期( # 39;Y # 39,$datetime),日期( # 39;n # 39,$datetime)),$ zbp- gt;郎[ # 39;msg # 39][#39;年_月 # 39;]);
$ w[]= array( # 39; # 39;, #39;log _ PostTime # 39,$datetime,strtotime( # 39;+1个月 # 39;,$ datetime));
}
}

如果(!is _ null($ tags)){
$ Tag = new Tag;
if(is _ array($ tags)){
$ ta = array();
foreach($ tags as $ t){
$ ta[]= array( # 39;log _ Tag # 39, #39;%{#39;。$ t->;身份证。#39;}%#39;);
}
$ w[]= array( # 39;array _ like # 39,$ ta);
unset($ ta);
} else {
if(is _ int($ tags)){
$ tag = $ zbp- gt;GetTagByID($ tags);
} else {
$ tag = $ zbp- gt;GetTagByAliasOrName($ tags);
}
if($ tag- gt;ID gt0){
$ w[]= array( # 39;比如 # 39;, #39;log _ Tag # 39, #39;%{#39;。$ tag- gt;身份证。#39;}%#39;);
}
}
}

if(is _ string($ search)){
$ search = trim($ search);
if($搜索!==#39;#39;){
$ w[]= array( # 39;搜索 # 39;, #39;log _ Content # 39, #39;log _ Intro # 39, #39;log _ Title # 39,$ search);
}
}

如果(!empty($ order)){
if($ order = = # 39;新 # 39;){
$ order = array( # 39;log _ PostTime # 39= gt#39;desc # 39;);
}
if($ order = = # 39;热 # 39;){
$ order = array( # 39;log _ ViewNums # 39= gt#39;desc # 39;);
}
if($ order = = # 39;comm # 39){
$ order = array( # 39;log _ CommNums # 39= gt#39;desc # 39;);
}
if($ order = = # 39;兰德 # 39;){
$ order = array( # 39;兰德() # 39;= gt#39;#39;);
}
}

$ articles = $ zbp- gt;GetArticleList( # 39;*#39;、$w、$order、$count、null、false);

if($ option[ # 39;is _ related # 39]){
foreach($ articles as $ k = gt;$ a){
if($ a- gt;ID = = $ option[ # 39;is _ related # 39])
未设置($ articles[$ k]);
}
if(count($ articles)= $ count){
array _ pop($ articles);
}
}

返回$ articles

}

然后在我们需要的接口模板中调用。

随机文章

{$array=TcgetList(10,null,null,null,null,null,null, # 39;兰德 # 39;);}
lt;ul id = quot相关 quot gt
{ foreach $ array as $ related }
lt;李 gt ltspan class = quot时间 quot gt{ $相关。时间( # 39;医学博士 # 39;)} lt/spangt。 ltspan class = quot标题 quot gt lta href = quot{ $相关。Url } quottitle = quot{ $相关。Title } quot gt{ $相关。Title } lt/a gt; lt/spangt。 lt/李 gt
{/foreach }
lt;/ul gt;

随机10篇文章

b-热门文章

{$array=TcgetList(10,null,null,null,null,null,null, # 39;热 # 39;);}
lt;ul id = quot相关 quot gt
{ foreach $ array as $ related }
lt;李 gt ltspan class = quot时间 quot gt{ $相关。时间( # 39;医学博士 # 39;)} lt/spangt。 ltspan class = quot标题 quot gt lta href = quot{ $相关。Url } quottitle = quot{ $相关。Title } quot gt{ $相关。Title } lt/a gt; lt/spangt。 lt/李 gt
{/foreach }
lt;/ul gt;

调用10篇热门文章

热门评论文章

{$array=TcgetList(10,null,null,null,null,null,null, # 39;comm # 39;}
lt;ul id = quot相关 quot gt
{ foreach $ array as $ related }
lt;李 gt ltspan class = quot时间 quot gt{ $相关。时间( # 39;医学博士 # 39;)} lt/spangt。 ltspan class = quot标题 quot gt lta href = quot{ $相关。Url } quottitle = quot{ $相关。Title } quot gt{ $相关。Title } lt/a gt; lt/spangt。 lt/李 gt
{/foreach }
lt;/ul gt;

调用10篇热评文章。

可以根据我们的实际使用情况来调用。

欢迎分享,转载请注明来源:聚客百科

原文地址: http://juke.outofmemory.cn/life/712288.html

()
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-13
下一篇 2022-07-13

发表评论

登录后才能评论

评论列表(0条)

保存