ZBLOG PHP调用随机文章、热门文章、热评文章脚本方法
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

在定制ZBLOG PHP模板的过程中,可能有需要用到调用随机文章和热门文章等解决方法,这里蜗牛有看到@唐朝同学博客中有这样的脚本整理。我这边也转载过来,下次有使用的时候再测试实用性,如果有问题在进行更新。
使用方法:
第一、在我们的主题目录中需要创建include.php文件,如果有就直接添加脚本
function TcgetList($count = 10, $cate = null, $auth = null, $date = null, $tags = null, $search = null, $option = null,$order=null) {
global $zbp;
if (!is_array($option)) {
$option = array();
}
if (!isset($option[\\’only_ontop\\’]))
$option[\\’only_ontop\\’] = false;
if (!isset($option[\\’only_not_ontop\\’]))
$option[\\’only_not_ontop\\’] = false;
if (!isset($option[\\’has_subcate\\’]))
$option[\\’has_subcate\\’] = false;
if (!isset($option[\\’is_related\\’]))
$option[\\’is_related\\’] = false;
if ($option[\\’is_related\\’]) {
$at = $zbp->GetPostByID($option[\\’is_related\\’]);
$tags = $at->Tags;
if (!$tags)
return array();
$count = $count + 1;
}
if ($option[\\’only_ontop\\’] == true) {
$w[] = array(\\’=\\’, \\’log_IsTop\\’, 0);
} elseif ($option[\\’only_not_ontop\\’] == true) {
$w[] = array(\\’=\\’, \\’log_IsTop\\’, 1);
}
$w = array();
$w[] = array(\\’=\\’, \\’log_Status\\’, 0);
$articles = array();
if (!is_null($cate)) {
$category = new Category;
$category = $zbp->GetCategoryByID($cate);
if ($category->ID > 0) {
if (!$option[\\’has_subcate\\’]) {
$w[] = array(\\’=\\’, \\’log_CateID\\’, $category->ID);
} else {
$arysubcate = array();
$arysubcate[] = array(\\’log_CateID\\’, $category->ID);
foreach ($zbp->categorys[$category->ID]->SubCategorys as $subcate) {
$arysubcate[] = array(\\’log_CateID\\’, $subcate->ID);
}
$w[] = array(\\’array\\’, $arysubcate);
}
}
}
if (!is_null($auth)) {
$author = new Member;
$author = $zbp->GetMemberByID($auth);
if ($author->ID > 0) {
$w[] = array(\\’=\\’, \\’log_AuthorID\\’, $author->ID);
}
}
if (!is_null($date)) {
$datetime = strtotime($date);
if ($datetime) {
$datetitle = str_replace(array(\\’%y%\\’, \\’%m%\\’), array(date(\\’Y\\’, $datetime), date(\\’n\\’, $datetime)), $zbp->lang[\\’msg\\’][\\’year_month\\’]);
$w[] = array(\\’BETWEEN\\’, \\’log_PostTime\\’, $datetime, strtotime(\\’+1 month\\’, $datetime));
}
}
if (!is_null($tags)) {
$tag = new Tag;
if (is_array($tags)) {
$ta = array();
foreach ($tags as $t) {
$ta[] = array(\\’log_Tag\\’, \\’%{\\’ . $t->ID . \\’}%\\’);
}
$w[] = array(\\’array_like\\’, $ta);
unset($ta);
} else {
if (is_int($tags)) {
$tag = $zbp->GetTagByID($tags);
} else {
$tag = $zbp->GetTagByAliasOrName($tags);
}
if ($tag->ID > 0) {
$w[] = array(\\’LIKE\\’, \\’log_Tag\\’, \\’%{\\’ . $tag->ID . \\’}%\\’);
}
}
}
if (is_string($search)) {
$search=trim($search);
if ($search!==\\’\\’) {
$w[] = array(\\’search\\’, \\’log_Content\\’, \\’log_Intro\\’, \\’log_Title\\’, $search);
}
}
if(!empty($order)){
if($order==\\’new\\’){
$order = array(\\’log_PostTime\\’=>\\’DESC\\’);
}
if($order==\\’hot\\’){
$order = array(\\’log_ViewNums\\’=>\\’DESC\\’);
}
if($order==\\’comm\\’){
$order = array(\\’log_CommNums\\’=>\\’DESC\\’);
}
if($order==\\’rand\\’){
$order = array(\\’rand()\\’=>\\’ \\’);
}
}
$articles = $zbp->GetArticleList(\\’*\\’, $w, $order, $count, null, false);
if ($option[\\’is_related\\’]) {
foreach ($articles as $k => $a) {
if ($a->ID == $option[\\’is_related\\’])
unset($articles[$k]);
}
if (count($articles) == $count){
array_pop($articles);
}
}
return $articles;
}
然后就是在我们需要的界面模板中调用。
A – 随机文章
{$array=TcgetList(10,null,null,null,null,null,null,\\’rand\\’);}
<ul id=\\”related\\”>
{foreach $array as $related}
<li><span class=\\”time\\”>{$related.Time(\\’m-d\\’)}</span><span class=\\”title\\”><a h=\\”{$related.Url}\\” title=\\”{$related.Title}\\”>{$related.Title}</a></span></li>
{/foreach}
</ul>
随机10篇文章
B – 热门文章
{$array=TcgetList(10,null,null,null,null,null,null,\\’hot\\’);}
<ul id=\\”related\\”>
{foreach $array as $related}
<li><span class=\\”time\\”>{$related.Time(\\’m-d\\’)}</span><span class=\\”title\\”><a h=\\”{$related.Url}\\” title=\\”{$related.Title}\\”>{$related.Title}</a></span></li>
{/foreach}
</ul>
调用10篇热门文章
C – 热评文章
{$array=TcgetList(10,null,null,null,null,null,null,\\’comm\\’;}
<ul id=\\”related\\”>
{foreach $array as $related}
<li><span class=\\”time\\”>{$related.Time(\\’m-d\\’)}</span><span class=\\”title\\”><a h=\\”{$related.Url}\\” title=\\”{$related.Title}\\”>{$related.Title}</a></span></li>
{/foreach}
</ul>
调用10篇热评文章。
具体的根据我们实际使用调用就可以。
猜你可能想看的VPS
- 便宜 $19 月 E5-2670 8G 内存 500G 硬盘 10T 流全球[VPS测评]
- 企鹅小屋→300 元 月 2*L56XX 16GB 内存 1TB 硬盘 香港VPS[主机]
- PuzCloud→103.2 元 季 1GB 内存 10GB 空间 50虚拟空间(主机)
- 腾讯→我的医保 免费领取 3 个现金红包 秒到微信零钱全球[VPS测评]
- 极安主机→CDN 有新加坡 韩国 香港 美国等节点 5Mbps 带宽 不韩国VPS[主机]
- Netcup→€20.99 月 6 核独享 32GB 内存 480GB 虚拟空间(主机)
- 特价 RackNerd→洛杉矶 纽约机房站群服务器 优化线路 MC 机房站群服务器[IP]
- RAKsmart 十月活动→圣何塞 258IP 站群服务器 197 美元站群服务器[IP]
- 魔方云→香港 HKBN NAT 动态 IP 自动更换 KVM 虚拟架构 香港VPS[主机]
- c4o→15 元 月 1.5GB 内存 20GB SSD 空间 不限流量虚拟空间(主机)
- 疯狂猜成语 图猜成语一个人身上插着一把剑旁边一个仁字是什么成语?全球[VPS测评]
- DogYun 新年动态云全场 7 折 抽奖送流量送折扣 香港&日本&德国日本VPS[主机]
- 谷歌浏览器Google Chrome版本大全全球[VPS测评]
- CloudServer 8G 4核CPU 100G纯SSD 5T大流量月全球[VPS测评]
- VirMach黑五便宜KVM VPS降价,年付最低6.30美元起,机不可全球[VPS测评]
- iwhost → 7.8$ 月 马来西亚VPS 1C1G25G 2IP全球[VPS测评]
- CloudCone → 256M 内存 10G 储存 1T流量 年付$1全球[VPS测评]
- 缓解云计算人才焦渴,苏州工业园区用三年引得源头活水来全球[VPS测评]
- 日主机,便宜美国CN2高防VPS¥19/月起,1Gbps带宽,香港多IP站群服务器[IP]
- 新华全媒+丨第六届全球跨境电商大会:跨境电商加快拓宽中国贸易新通道全球[VPS测评]
- MoonVM,香港HKT家宽VPS服务器,动态IP一键切换,1G带宽任意香港VPS[主机]
- 一篇漫画,看懂云计算全球[VPS测评]
- 阿里行癫:如何理解当下的云计算全球[VPS测评]
- 企鹅小屋怎么样?深港IPLC专线销售 500M大带宽/2核1G内存/55全球[VPS测评]
- 者也vps年终特惠:全场云服务器7折终身优惠,赠1G内存,充1000送3全球[VPS测评]
- 消费复苏形势良好,我们将多措并举实施扩大内需政策全球[VPS测评]
- 亿速云11.11上云狂欢节活动:2核4G国内/香港云服务器,价格999元香港VPS[主机]
- Ubuntu关机命令是什么?Ubuntu关机命令介绍全球[VPS测评]
- 亿速互联怎么样?香港沙田vps,2核1G3M云主机仅98元/月,780元香港VPS[主机]
- 乐趣云怎么样?香港美国云服务器首月8.8元,新增IP5元/个美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-142865.html











