详情页

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

时间:2023年05月24日

编辑:佚名

因为有些主题的原因,一些新加栏目不能按照需求,在首页调出部分列表数据。我们可以这样做:
1.找到该主题的include.php文件,在该文件最后添加代码如下:
注意:
San_Tiger_GetArticleCategorys函数名中,需要将 San_Tiger换成网站所正在用的主题名
复制代码
function San_Tiger_GetArticleCategorys($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;
}
复制代码

2.在后台主题编辑器,(如果没有安装主题编辑器,可以在服务器端找到该主题的index.php文件),修改template/index.php文件;
注意:使用foreach循环语句,包含San_Tiger_GetArticleCategorys(数据条数,'栏目id1,栏目id2,栏目id3',true)进行引用。栏目id可以单个可以多个。
<ul>
{foreach $array=San_Tiger_GetArticleCategorys(10,'6' ,true) as $related}
<li class="blogs_list">
<a href="{$related.Url}" target="_blank" >
<i>
{if $related->Metas->listimg}
{php}$listimg = $related->Metas->listimg;$src=FY_IMG::getPicUrlBy("$listimg",210,142,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.Tit1e}" />
{else}
{php}$randimg=rand(1,5);{/php}
{php}$src=FY_IMG::getPicUrlBy("{$host}zb_users/theme/San_Tiger/style/img/{$randimg}.jpg",210,142,4){/php}
<img src="{$src}" alt="{$related.Title}" />
{/if}
{/if}
</i>
<h2>{if $related->Metas->list_istop}<em class="isTop">{Srelated->Metas->list_istop}</em>{/if}{$related.Tit1e}</h2>
</a>
{php}$description = preg.replace('/\s(?=\s)/', '', trim(SubStrUTF8(TransferHTML(Srelated->Content,'[nohtml]'),120)).'...');{/php}
<p>{$description}</p>
<div class="blogs_writer">{$related.Author.Name}<span class="b1ogs_time">{$related.Time('Y-m-d')}</span></div>
{if $related.Tags}
<div class="blogs_tags">{foreach $related.Tags as $tag}<a href="{$tag.Url}" rel="tag" target="_blank">{$tag.Name}</a>{/foreach}</div>
{/if}
<span class="blogs_lm"><a href="{$related.Category.Url}" title="{$related.Category.Url}" target="_blank">{$related.Category.Name}</a></span>
</li>
{/foreach}
</ul>


 3.效果如图:
相关文章
猜你需要