我不得不承认,我很难看到Wordpress 214主题是如何从主题的page-templates
文件夹之前,我会创建名为page-<slug>.php
在主题的根文件夹中,但不是现在。
我在代码中搜索了page-templates
未发现任何包含文件的地方;也搜索了WP源代码,但没有找到。
你能解释一下它们是如何被发现和拾起的吗?
我不得不承认,我很难看到Wordpress 214主题是如何从主题的page-templates
文件夹之前,我会创建名为page-<slug>.php
在主题的根文件夹中,但不是现在。
我在代码中搜索了page-templates
未发现任何包含文件的地方;也搜索了WP源代码,但没有找到。
你能解释一下它们是如何被发现和拾起的吗?
对主题页面模板的实际查询发生在wp_get_theme()->get_page_templates()
(source), 依次调用get_files()
(source).
$files = (array) $this->get_files( \'php\', 1 );
的参数get_files()
是:function get_files( $type = null, $depth = 0, $search_parent = false ) {}
因此,当WordPress在主题中搜索PHP文件时,它会传递一个$depth
的参数1
, 这意味着它在主题根目录的子目录中搜索。任何page-slug.php
模板或用作页面模板的模板是将页面标识为页面模板的标题部分。示例contributors.php
:
/**
* Template Name: Contributor Page
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
模板名称将其标识为名为“Contributors page”的页面模板。页面模板不需要以任何方式注册或调用,就可以在主题中使用。无论它们在主题中的哪个位置,都会自动包含它们。页面模板不必在根文件夹中才能“拾取”。然而,在214中,这些模板被赋予了一个body类,因此需要调用模板的完整路径。
if ( ( ! is_active_sidebar( \'sidebar-2\' ) )
|| is_page_template( \'page-templates/full-width.php\' )
|| is_page_template( \'page-templates/contributors.php\' )
|| is_attachment() ) {
$classes[] = \'full-width\';
}
我不得不承认,我很难看到Wordpress 214主题是如何从主题的page-templates
文件夹之前,我会创建名为page-<slug>.php
在主题的根文件夹中,但不是现在。
我在代码中搜索了page-templates
未发现任何包含文件的地方;也搜索了WP源代码,但没有找到。
你能解释一下它们是如何被发现和拾起的吗?
对主题页面模板的实际查询发生在wp_get_theme()->get_page_templates()
(source), 依次调用get_files()
(source).
$files = (array) $this->get_files( \'php\', 1 );
的参数get_files()
是:function get_files( $type = null, $depth = 0, $search_parent = false ) {}
因此,当WordPress在主题中搜索PHP文件时,它会传递一个$depth
的参数1
, 这意味着它在主题根目录的子目录中搜索。任何page-slug.php
模板或用作页面模板的模板是将页面标识为页面模板的标题部分。示例contributors.php
:
/**
* Template Name: Contributor Page
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
模板名称将其标识为名为“Contributors page”的页面模板。页面模板不需要以任何方式注册或调用,就可以在主题中使用。无论它们在主题中的哪个位置,都会自动包含它们。页面模板不必在根文件夹中才能“拾取”。然而,在214中,这些模板被赋予了一个body类,因此需要调用模板的完整路径。
if ( ( ! is_active_sidebar( \'sidebar-2\' ) )
|| is_page_template( \'page-templates/full-width.php\' )
|| is_page_template( \'page-templates/contributors.php\' )
|| is_attachment() ) {
$classes[] = \'full-width\';
}