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

在定制ZBLOG PHP模板的过程中,可能有需要用到调用随机文章和热门文章等解决方法,[email protected]!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()��。我这边也转载过来,下次有使用的时候再测试实用性,如果有问题在进行更新。
使用方法:
第一、在我们的主题目录中需要创建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
- zji→香港葵湾 cn2+bgp 网络 549 元 E5-2650L 1香港VPS[主机]
- 看奈飞 $30 月 1GB 内存 10GB SSD 3TB 流量 100全球[VPS测评]
- 疯狂猜成语 图猜成语一个袋子里面装着枪和头盔是什么成语?全球[VPS测评]
- CN2 GIA $34.5 年 768M 内存 35G 硬盘 600G 全球[VPS测评]
- 便宜的免备案虚拟主机-Hostens 虚拟主机月付低至 0.99 美元全球[VPS测评]
- 腾讯云服务器+云通信产品组合低至 1 折起,2 核 4G 2 核 8G 全球[VPS测评]
- CenterHop→$1.5 月 256MB 内存 5GB SSD 空间虚拟空间(主机)
- Gnu Host→£5 月 50GB SSD 空间 不限流量 不限绑定域虚拟空间(主机)
- 优惠 MoeCloud→美国原生 IP CN2 GIA 线路 可看奈飞 美国VPS[主机]
- €6 月 高频 CPU 2G 内存 50G SSD 500Mbps 不限全球[VPS测评]
- 黑五 Losangelesvps→全场 4 折优惠 洛杉矶 1G 不限流全球[VPS测评]
- 黑色星期五 hostsolutions→9 欧 年 1G 内存 10T 全球[VPS测评]
- 硅云香港云服务器促销,免备案 100%CPU 性能,最高 80M 带宽,香港VPS[主机]
- 宝塔面板免费版如何开启 waf 防火墙全球[VPS测评]
- 如何阻止Windows Update捆绑更新设备驱动WINDOWS
- ZJI新上架香港华为云cn2线路独立服务器,下单月付立减300元,终身优独立服务器[U]
- JUSTHOST → 23¥月付 香港 1C0.5G5G硬盘 200Mb香港VPS[主机]
- 喵云 → 双十一75折 月付7元起 台湾HiNet NAT 香港HGC 香港VPS[主机]
- 宝塔面板怎么放行端口?宝塔面板放行端口的方法全球[VPS测评]
- 九零云怎么样?香港将军澳VPS,美国圣何塞VPS 2核1G10M 47/美国VPS[主机]
- 快速云:云服务器和vps区别是什么云服务器和vps哪个比较安全2022-全球[VPS测评]
- CMCUCT:2核2GB/20GB香港ntt线路vps 6TB流量/1G香港VPS[主机]
- 月神云:洛杉矶CN2 GIA高防vps、香港CN2 GIA VPS全场7香港VPS[主机]
- CubeCloud,香港cn2,美国cn2 gia线路vps主机,2核1美国VPS[主机]
- 搬瓦工:美国香港cn2 gia线路VPS,10Gbps带宽,移动+联通企美国VPS[主机]
- 做跨境电商一个月都有多少收入?全球[VPS测评]
- 谷歌浏览器网址如何显示http,www,Chrome谷歌浏览器恢复地址栏全球[VPS测评]
- 咖啡主机:新上香港云服务器、美国CN2轻量级KVM vps,香港15.6美国VPS[主机]
- HostKvm:1核/4G/30G硬盘/750G/20Mbps/香港kv香港VPS[主机]
- 私有云架设之优选拓普龙S465-24高密度存储服务器机箱评测解析全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-39864.html











