什么是singular.php?


13

从4.3开始,我们有了一个新模板singular.php。我试图了解它是什么,但没有得到。:)

的page.php页面。在single.php为每一个岗位类型。如果我们有single-[post-type].php,我们可以使用自定义后类型的特定模板..所以我们为什么需要singular.php?

Answers:


14

这是本质的WordPress模板层次 -点的存在,如果你不有page.php,它会使用singular.php,同样的,如果你没有single.php,它会回退到模板中的较低层次。

是帖子/页面具有相同布局的主题的理想选择,而不是每个相应模板中都有重复的代码。


13

singular.php对于所有帖子类型,基本上都是额外的备用,无论是内置还是自定义。它紧接在single.php和之后page.php,因此您可以省略后两个模板,而只有一个singular.php模板,该模板将在单个视图中供所有帖子类型使用。

就像任何其他模板一样,它的有用性和必要性取决于用户/站点/需求。模板层次结构的构建使得无论查看哪个页面,您始终只需要index.php显示任何页面。因此,在短期,你可以有一个全功能的主题,只有index.php和style.csstheme文件夹中。

模板层次结构中可用的模板只是为了方便起见,也是如此singular.php。您可以根据需要在上下文中使用任何模板,但是如果不需要,则不必使用它。


2

单个帖子模板文件用于呈现单个帖子。WordPress使用以下路径:

1.single- {post-type} .php –首先,WordPress寻找用于特定帖子类型的模板。例如,帖子类型为product,WordPress将查找single-product.php。

2.single.php –然后WordPress退回到single.php。

3.singular.php –然后回落到singular.php。

4.index.php –最后,如上所述,WordPress最终退回到index.php。

https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post

用于呈现静态页面的模板文件(页面后置类型)。请注意,与其他帖子类型不同,页面是WordPress专用的,并使用以下修补程序:

1.custom template文件–分配给页面的页面模板。请参见get_page_templates()。

2.page- {slug} .php –如果页面slug是最近新闻,WordPress将使用page-recent-news.php。

3.page- {id} .php –如果页面ID为6,则WordPress将使用page-6.php。

4.page.php

5.singular.php

6.index.php

https://developer.wordpress.org/themes/basics/template-hierarchy/#page


singular.php也是page.php
— Pieter Goosen 2015年

是的,它也是page.php的后备平台
— 马修(

添加了page.php
— matthew
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.