将Wordpress主题模板文件移动到子目录
我想在我正在创建的Wordpress主题中重新构造模板文件。现在,像将Wordpress主题模板文件移动到子目录,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我想在我正在创建的Wordpress主题中重新构造模板文件。现在,像single.php和archive.php这样的文件位于我的主题的根级别。我想将它们移动到它们自己的文件夹中——比如一个名为pages的文件夹。这样看起来就像这样: mytheme -- pages -- archive.php -- single.php -- functions.php -- index.php -- style.css 这可能吗?如果是,怎么做 谢谢。您可以使用
single.php
和archive.php
这样的文件位于我的主题的根级别。我想将它们移动到它们自己的文件夹中——比如一个名为pages
的文件夹。这样看起来就像这样:
mytheme
-- pages
-- archive.php
-- single.php
-- functions.php
-- index.php
-- style.css
这可能吗?如果是,怎么做
谢谢。您可以使用
单一\u模板
过滤器和{$type}\u模板
过滤器对存档、类别等进行过滤
我想这就是你要找的东西:
function get_new_single_template( $single_template ) {
global $post;
$single_template = get_stylesheet_directory() . '/pages/single.php';
return $single_template;
}
add_filter( 'single_template', 'get_new_single_template' );
function get_new_archive_template( $archive_template ) {
global $post;
$archive_template = get_stylesheet_directory() . '/pages/archive.php';
return $archive_template;
}
add_filter( 'archive_template', 'get_new_archive_template' );
这将转到functions.php