首页 后端内容详情

Zblog:如何在内容页调用本栏目最新和最热文章?

2023-01-06 297 五九四十八

步骤:

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}
复制代码

 相关推荐:

Zblog:如何在首页调用不同栏目的列表数据?