admin管理员组文章数量:1407737
tell me where to refer to the function to be run once at the start of the page.
Exactly I mean to set a specific template so that every time you open the page always the same template loads without regard to what template was set up in the back.
tell me where to refer to the function to be run once at the start of the page.
Exactly I mean to set a specific template so that every time you open the page always the same template loads without regard to what template was set up in the back.
Share Improve this question edited Feb 26, 2020 at 18:15 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 26, 2020 at 18:10 spokspok 72 bronze badges 1- If you are in controll of the template files, leaving only your index.php left should route everything to that template file. – Luckyfella Commented Feb 26, 2020 at 18:24
1 Answer
Reset to default 1This question is quite difficult to understand.
Do you mean you want to make generic template pages Programmatically? There are a few ways to do this.
If you have a page built on the backend, you can create a file within your theme folder called page-{page-name}.php. For instance, for a page called about, you should create a file called page-about.php.
If it is a post, the same logic applies, but with single-{post-name}.php.
Alternatively, if you want a template page for several pages under one file, you could use a conditional statement along with the is_page() function inside page.php (or single.php for posts).
You can also use get_post_field with a conditional, as such:
if ('contact-us' == get_post_field( 'post_name', $post->post_parent )) {
get_template_part( 'template-parts/contact', 'page' );
exit;
} else if ('volunteer-with-us' == get_post_field( 'post_name')) {
get_template_part( 'template-parts/contact', 'page' );
exit;
}
本文标签: Force template on page load
版权声明:本文标题:Force template on page load 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744712996a2621236.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论