singular.php:WordPress 4.3新增主题模板

分享本文:
singluar-feature

WordPress开发团队昨天发布消息称,WordPress 4.3版本将会在主题体系中增加一个新模板:singular.php 。从功能上讲,该模板singluar.php类似于single.php,page.php;区别在于,新模板与文章类型无关。

这是一个非常令人振奋的消息。WordPress开发团队官方博客中,是这样介绍singluar.php模板的:

A new theme template has been added to the theme hierarchy as of r32846: singular.php.  This template follows the rules of is_singular and is used for a single post, irregardless of post type.  It comes in the hierarchy after single.php, page.php, and the variations of each. Themes that used the same code for both of those files (or included one in the other) can now simplify down to the one template.

之前,在WordPress的主题体系中,主要依赖single.php模板显示单篇的博客文章,依赖page.php模板显示单篇的静态页面。如果你想要展示单篇的其他类型内容,比如自定义的作品类型等,设计师需要额外的技巧进行判断和处理。

现在,singular.php模板文件配合is_singluar函数,一切都变得简单了。如同设计single.php和page.php模板的不同版本一样,设计师可以轻松设计出针对不同类型内容的单篇模板。

在WordPress模板体系中,singluar.php模板的优先级低于single.php,page.php,以及这二者的各种变形版本。

分享本文:


发表一下评论

邮箱地址不会被公开。 必填项已用*标注