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
- 秒杀 腾讯云→1 核 1G 1M 香港免备案套餐年付¥249 2 核 4香港VPS[主机]
- bacloud→8.5 折优惠 1Gbps 不限流量 VPS 除美国 立美国VPS[主机]
- DediPath→$175 月 E3-1270v2 16GB 内存 2T全球[VPS测评]
- ThinkPHP5.1 中使用 phpqrcode 生成二维码全球[VPS测评]
- STSDUST→$5.33 月 1GB 内存 20GB SSD 空间 1虚拟空间(主机)
- 做站 傲游主机新上圣何塞 CN2 GIA 线路 年付自动 8.3 折 可全球[VPS测评]
- HostKvm 新上洛杉矶CN2VPS 2G内存入门套餐七折终身优惠$6全球[VPS测评]
- WordPress网站引入腾讯vConsole调试面板方便手机端页面调试全球[VPS测评]
- 欧路云新上美国 CN2 GIA 高防VPS,三网回程CN2GIA线路,1美国VPS[主机]
- WordPress网站代码实现网站弹窗广告全球[VPS测评]
- SoftShellWeb 黑五促销 中国台湾大陆优化线路 1g内存 带5全球[VPS测评]
- George Datacenter-17.5$ 年 达拉斯 1核AMD2全球[VPS测评]
- BuyVM → 卢森堡 DMCA友好 无限流量全球[VPS测评]
- GreenCloudVPS → 新加坡存储机型 → 2G 500G 全球[VPS测评]
- Wikihost(idc.wiki) → 日本CN2 去程163回程C日本VPS[主机]
- 恒创科技怎么样?香港美国云服务器/独服/高防全场2.5折起美国VPS[主机]
- 磐逸云怎么样?香港沙田cn2vps 带宽5M年付128元香港VPS[主机]
- 桔子数据,香港安畅BGP大带宽VPS 首月五折体验 三网直连 14元/月香港VPS[主机]
- 精编案例丨游戏行业转型升级迫在眉睫,云计算助力打造下一代游戏体验全球[VPS测评]
- tudcloud:香港vps/2核/2GB/20GB空间/不限流量/KV虚拟空间(主机)
- 潮科技|阿里云发布第七代高主频云服务器ECS和含光800云服务器全球[VPS测评]
- 二三互联,香港cn2云服务器5折+85折双重优惠,稳定不限流量,1核1G香港VPS[主机]
- 六六云:1核/1GB/20GB硬盘/500GB流量/30Mbps/KVM香港VPS[主机]
- 用玩客云做打印服务器,让你在手机上轻松实现无线打印全球[VPS测评]
- vpsplayer:新年活动_vps全部7.5折起_深圳BGP/美西Ce香港VPS[主机]
- LOCVPS,全新香港大浦CN2 VPS 2核4G内存3M仅54/月香港VPS[主机]
- 数字化东风已来,亚马逊云科技跨境电商合作企业招募大会即将开启全球[VPS测评]
- 拼多多也要做跨境电商?出海之路能一帆风顺吗,了解一下全球[VPS测评]
- 易凡云:国内洛阳BGP,辽宁BGP防CC,云服务器低至48.26元/月,香港VPS[主机]
- 亿恩科技香港云服务器 2核2G服务器特价700元/年香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-142865.html











