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}

 相关推荐:

Zblog:如何在首页调用不同栏目的列表数据?
posted @ 2022-07-25 13:22  coderjim  阅读(470)  评论(0编辑  收藏  举报

更多知识请点击——

www.7017online.xyz