我目前正在为各种博客格式创建一些模板,例如;\'旁白、“引用”和“图库”。
我看到很多人通过将这些文件命名为以下文件来创建此类模板:
content-aside.php
content-quote.php
content-gallery.php
format-aside.php
format-quote.php
format-gallery.php
我目前正在为各种博客格式创建一些模板,例如;\'旁白、“引用”和“图库”。
我看到很多人通过将这些文件命名为以下文件来创建此类模板:
content-aside.php
content-quote.php
content-gallery.php
format-aside.php
format-quote.php
format-gallery.php
不应该有任何问题,不要忘记更改模板部件调用中的slug:
get_template_part( \'format\', get_post_format() );
最佳做法是将它们放在自己的文件夹中:get_template_part( \'template-parts/post/format\', get_post_format() );
您可以看到的文件夹结构twentyseventeen
只要换一下content
分别地How get_template will work:
get_template_part
将对找到的第一个文件执行PHP require(),它将创建第一个项数组将使用的数组slug
和name
像这样:
{$slug}-{$name}.php
第二个项目数组将是:{$slug}.php
函数将迭代文件名数组,直到找到存在的文件名为止。因此,如果您执行以下操作:
get_template_part( \'format\', get_post_format() );
例如,格式为video
文件名数组将为:[0] "format-video.php"
[1] "format.php"
它将回退到format.php
, 如果是Child theme
优先顺序如下video
格式示例:[0] "format-video.php" //in child theme
[1] "format-video.php" //in parent theme
[2] "format.php" //in child theme
[3] "format.php" // in parent theme
我希望我的WordPress遵循以下规则:/productes/ 包含所有产品的页面/productes/[category]/ 包含该类别所有产品的分类页面/productes/[category]/[subcategory]/ 包含该类别所有产品(与2相同)的分类页面/[productes]/[category]/[product]/ A.single-productes.php 将显示类别产品/[productes]/[category]/[subcategory]/[product]/ A.sin