WordPress:index.php 与 home.php?
Wordpress: index.php vs home.php?
我正在阅读本教程 Wordpress theming 关于将 html 站点转换为 WP,它说
WordPress has a hierarchy of templates. None of them are called index
(that name is reserved) so we need to rename our index file to
something else.
因此,根据教程,我将 index.html 重命名为 home.php。但是当我转到主题时,它说主题已损坏,因为它缺少模板并且仅当我将 home.php 重命名为 index.php.
时它才显示为有效主题
我应该使用 index.php 还是保留 home.php,它会在我有其他页面(如 header.php 等)后识别它?
ps。教程已过时?
来自 codex:
At the very minimum, a WordPress Theme consists of two files:
style.css
index.php
您需要保留 index.php 文件。
home.php 也被 wordpress 模板用作 front page 的选项作为网站主页而不是默认博客页面 - index.php.
home.php
The home page template, which is the front page by default.
If you use a static front page this is the template for the page with
the latest posts.
如果您想为主页创建一个新模板,您可以为 new custom template 创建一个新的 php 文件,并将 "template name" 放在文件的开头:
<?php
/*
Template Name: my template
*/
然后从管理面板将名为 'home' 的页面设置为您的新模板。
我正在阅读本教程 Wordpress theming 关于将 html 站点转换为 WP,它说
WordPress has a hierarchy of templates. None of them are called index (that name is reserved) so we need to rename our index file to something else.
因此,根据教程,我将 index.html 重命名为 home.php。但是当我转到主题时,它说主题已损坏,因为它缺少模板并且仅当我将 home.php 重命名为 index.php.
时它才显示为有效主题我应该使用 index.php 还是保留 home.php,它会在我有其他页面(如 header.php 等)后识别它?
ps。教程已过时?
来自 codex:
At the very minimum, a WordPress Theme consists of two files:
style.css
index.php
您需要保留 index.php 文件。 home.php 也被 wordpress 模板用作 front page 的选项作为网站主页而不是默认博客页面 - index.php.
home.php
The home page template, which is the front page by default. If you use a static front page this is the template for the page with the latest posts.
如果您想为主页创建一个新模板,您可以为 new custom template 创建一个新的 php 文件,并将 "template name" 放在文件的开头:
<?php
/*
Template Name: my template
*/
然后从管理面板将名为 'home' 的页面设置为您的新模板。