Zblog:如何在内容页调用本栏目最新和最热文章?
步骤:
1.找到主题include.php文件;创建最新、最热方法,放置在include.php最下面;
San_Tiger_GetArticleCategorys_new
San_Tiger_GetArticleCategorys_hot
最新文章:
function San_Tiger_GetArticleCategorys_new($Rows,$CategoryID,$hassubcate){ global $zbp; $ids = strpos($CategoryID,',') !== false ? explode(',',$CategoryID) : array($CategoryID); $wherearray=array(); foreach ($ids as $cateid){ if (!$hassubcate) { $wherearray[]=array('log_CateID',$cateid); }else{ $wherearray[] = array('log_CateID', $cateid); foreach ($zbp->categorys[$cateid]->SubCategorys as $subcate) { $wherearray[] = array('log_CateID', $subcate->ID); } } } $where=array( array('array',$wherearray), array('=','log_Status','0'), ); $order = array('log_PostTime'=>'DESC'); $articles= $zbp->GetArticleList(array('*'),$where,$order,array($Rows),''); return $articles; }
最热文章:
function San_Tiger_GetArticleCategorys_hot($Rows,$CategoryID,$hassubcate){ global $zbp; $ids = strpos($CategoryID,',') !== false ? explode(',',$CategoryID) : array($CategoryID); $wherearray=array(); foreach ($ids as $cateid){ if (!$hassubcate) { $wherearray[]=array('log_CateID',$cateid); }else{ $wherearray[] = array('log_CateID', $cateid); foreach ($zbp->categorys[$cateid]->SubCategorys as $subcate) { $wherearray[] = array('log_CateID', $subcate->ID); } } } $where=array( array('array',$wherearray), array('=','log_Status','0'), ); $order = array('log_ViewNums'=>'DESC'); $articles= $zbp->GetArticleList(array('*'),$where,$order,array($Rows),''); return $articles; }
2.在内容页模板 post-single.php文件中,调用循环:
{foreach $array=San_Tiger_GetArticleCategorys_hot(6,$article.Category.ID,true) as $related} <li> <a href="{$related.Url}" target="_blank"> <i> {if $related->Metas->listimg} {php}$listimg = $related->Metas->listimg;$src=FY_IMG::getPicUrlBy("$listimg",120,70,4);{/php} <img src="{$src}" alt="{$related.Title}" /> {else} {php}FY_IMG::getPics($related,210,142,4){/php} {if $related->fy_img_count>0} <img src="{$related.fy_img[0]}" alt="{$related.Title}" /> {else} {php}$randimg=rand(1,5);{/php} {php}$src=FY_IMG::getPicUrlBy("{$host}zb_users/theme/San_Tiger/style/img/{$randimg}.jpg",120,70,4){/php} <img src="{$src}" alt="{$related.Title}" /> {/if} {/if} </i> <h2>{$related.Title}</h2> <span>{$related.Time('Y-m-d')}</span> </a> </li> {/foreach}
相关推荐:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具