I\'m creating my own theme framework, and I want to organize my code, separating the partials files from the pages.
But I want to do that and still use the native functions get_header(), get_footer() and get_sidebar().
How can I change this functions to look for the templates on the directory partials/ instead of the theme\'s root directory?
最合适的回答,由SO网友:Nicolai Grossherr 整理而成
简单解决方案,使用get_template_part().
例如:
get_template_part( \'partials/footer\' );
这将得到
footer.php 内部
partials/ 目录
另一个例子:
get_template_part( \'partials/footer\', \'home\' );
这将得到
footer-home.php 内部
partials/ 目录
还有一个例子:
get_template_part( \'partials/footer/blog\' );
这将得到
blog.php 内部
partials/footer/ 目录