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
- 疯狂猜成语 图猜成语一个人抱着一袋金子在骂另一个人是什么成语?全球[VPS测评]
- layer 通过 parent.layer.open 打开的窗体向父窗体全球[VPS测评]
- Windows 系统 $42 年 4 核 CPU 40G SSD 5T WINDOWS
- 补货 Virmach→$1.25 月低配套餐补货 512M 及以上套餐终全球[VPS测评]
- KTS24→€2.5 月 4G 内存 25GB SSD 空间 5TB 流虚拟空间(主机)
- 补货通知 VirMach→512M 套餐圣何塞补货 速度不错 部分 IP全球[VPS测评]
- tmhhost 香港 cn2 多线 bgp 服务器 400 元 月起,4香港VPS[主机]
- 促销 JGKVM→洛杉矶 CN2 GIA 线路套餐补货 新推出 179 全球[VPS测评]
- 五一促销 edgeNAT→8 核 8G 40G SSD 4Mbps 不限韩国VPS[主机]
- WordPress网站搜索结果只有一篇文章代码实现自动跳转到该文章全球[VPS测评]
- 如何通过巧用WordPress Trackbacks和Pingbacks全球[VPS测评]
- 欧路云新上美国 CN2 GIA 高防VPS,三网回程CN2GIA线路,1美国VPS[主机]
- 百度搜索将打击网站搜索内容需获取权限才能查看的情况全球[VPS测评]
- GigsGigsCloud 新加坡 VPS CLOUDLET SG K1全球[VPS测评]
- Tiktalik-1.8$ 月 波兰华沙 2核1G内存20G硬盘 不计流全球[VPS测评]
- 双十二-修罗云8折循环折扣 常州联通VPS 国内NAT VPS 香港HK香港VPS[主机]
- Virmach 2019中国新年促-512M 10G ssd 500G年全球[VPS测评]
- GigsGigsCloud 循环三五折 三网最高级线路 独立服务独立服务器[U]
- DMIT日本Pro → 三网高级线路公开测试(Openbeta) → 2日本VPS[主机]
- 潮科技|阿里云发布第七代高主频云服务器ECS和含光800云服务器全球[VPS测评]
- 什么是Bootstrap?全球[VPS测评]
- 快速云:云服务器和vps区别是什么云服务器和vps哪个比较安全2022-全球[VPS测评]
- 网站迁移服务器是如何运作的?新手站长看完这篇文章,很容易就能看完。全球[VPS测评]
- tudcloud,香港vps终身八折$7.76/月起,1核1G内存,香港香港VPS[主机]
- 众创逸云:1核2G云服务器,不限流量vps/5Mbps/KVM/香港CN香港VPS[主机]
- 麻花云双12年终盛典:香港云主机9元起,老客户续费6折;安徽BGP线路v香港VPS[主机]
- 全球云lovps,香港CN2线路vps 新品七折月付49元香港VPS[主机]
- 港网科技怎么样?国内BGP云主机,2核2G5M带宽仅377.46元/年全球[VPS测评]
- 阳帝云双十二活动:1核1G10M大宽带香港BGP云服务器,月付14元香港VPS[主机]
- 阿里云香港服务器多少钱一年?香港阿里云服务器价格表香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-39864.html











