您现在的位置是: 首页 > 值得一看 > zblog教程

zblog教程

zblog首页和列表页分离 首页列表文章不显示置顶的方法

作者:网友投稿 时间:2023-05-08 阅读数:50

我们在做zblog主题的时候,需要在分类列表中显示置顶文章,而在首页不显示。

所以需要先把首页和列表页分离开来,index.php复制出三份,分别命名为index.php,default.php,list.php等等

index.php插入下面代码:

{if $type=='index'&&$page=='1'} /*判断首页*/
{template:default}
{elseif $type=='category'} /*判断分类页*/
{template:list}
{elseif $type=='article'} /*判断日志页,不含独立页面*/
{template:index_artile}
{elseif $type=='page'} /*判断独立页面*/
{template:index_page}
{elseif $type=='author'} /*判断用户页*/
{template:index_author}
{elseif $type=='date'} /*判断日期页*/
{template:index_date}
{elseif $type=='tag'} /*判断标签页*/
{template:index_tag}
{/if}

具体文件名称自己定义就可以了。

我们在default.php文件中找到下面代码:

{foreach $articles as $article}
{if $article.IsTop}
{template:post-istop}
{else}
{template:post-multi}
{/if}
{/foreach}

替换为:

{foreach $articles as $article}
{if $article.IsTop}
{else}
{template:post-multi}
{/if}
{/foreach}

这样置顶文章就不会显示在首页了,并不影响列表页置顶文章的显示。

可能喜欢