Z-BlogPHP主题制作教程#13:post-single和post-page

前段时间,我们讲解了了内容模版single.php。在里面,我们通过一个 if 逻辑判断,分别调用了两个不同的PHP模版,它们是:post-single.php和post-page.php。

{if $article.Type==ZC_POST_TYPE_ARTICLE}
{template:post-single}
{else}
{template:post-page}
{/if}
这个假设的逻辑就是,当“文章”是“文章”时,就使用普通的文章模版post-single.php,否则,就使用post-page.php。

讲到这里,很多人会很奇怪,什么叫“文章是文章”的判断?要理解这个,我们需要知道Z-BlogPHP里面几个不同的定义。

Z-BlogPHP里面有两种不同的文章类型:一种是博文类型,它们必然归集于某一个分类下;另外一种就是单独页面,它们无法被归集在一起。通常,我们发布一些特殊的通告、活动以及其他事项等就使用单独页面,而写的日常文章就是博文。博文文章因为它们有同样的一个分类,所以可以存在同类型文章(相关文章),上一篇、下一篇文章等的属性,而单独的页面不存在这样的东西。所以我们就也可以将它们这样理分开来来理解:post-single.php就是博文模版,而post-page.php是单独页面模版。

post-page.php单独页面模版:
post-page.php由两部分组成,一个 div 和一个评论框。好了,就这么多:

<div>
<h2>{$article.Title}</h2><!– 文章标题 –>
<div>{$article.Content}</div><!– 文章内容 –>
</div>

{if !$article.IsLock}<!– 评论框 –>
{template:comments}
{/if}

post-single.php博文模版:
post-single.php模版和post-page.php模板相似,只不过它会有分类和相关文章等信息。

有时候,我们为了增加文章的阅读性,会插入这些相关信息,比如文章发布的时间、文章作者、文章分类、浏览和评论情况等。所以完善下这个就大概变成这样:

<div>
<h4>{$article.Time(‘Y年m月d日’)}</h4><!– 文章发布时间 –>
<h2>{$article.Title}</h2>
<div>{$article.Content}</div>
<h6><!– 文章相关信息 –>
作者:{$article.Author.StaticName} | 分类:{$article.Category.Name} | 浏览:{$article.ViewNums} | 评论:{$article.CommNums}
</h6>
</div>

{if !$article.IsLock}
{template:comments}
{/if}
同样,我们可以引用《Z-BlogPHP主题制作技巧》中的一些方法来给他增加点相关文章:

<div>
<h4>{$article.Time(‘Y年m月d日’)}</h4><!– 文章发布时间 –>
<h2>{$article.Title}</h2>
<div>{$article.Content}</div>
<h6><!– 文章相关信息 –>
作者:{$article.Author.StaticName} | 分类:{$article.Category.Name} | 浏览:{$article.ViewNums} | 评论:{$article.CommNums}
</h6>
</div>
<div><!– 相关文章 –>
{foreach GetList(调用条数,分类ID) as $related}
<li>
<span>{$related.Time(‘Y-m-d’)}</span>
<a href=”{$related.Url}”>{$related.Title}</a>
</li>
{/foreach}
</div>

{if !$article.IsLock}
{template:comments}
{/if}