Rub*_*byx 1 php wordpress wordpress-theming
我正在尝试使用自定义模板为我的Wordpress设置自定义静态首页.
我创造landingpage.php的wp-content/themes/my_theme,我在我的模型的LandingPage WordPress管理中选择创建一个新的页面.
如果我去my_website.com/landing-page/我的自定义页面工作和'Hello World!' 出现了,但如果我将自定义页面设置为静态首页并转到my_website.com/我的"Hello World!" 消息不显示.
我的landingpage.php代码:
<?php /* Template Name: LandingPage */ ?>
<?php get_header(); ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/page/content', 'page' );
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile;
?>
<h1>Hello World!</h1>
</main>
</div>
</div>
<?php get_footer();
Run Code Online (Sandbox Code Playgroud)
任何的想法?谢谢
front-page.php 优先于您的自定义模板.
当该帖子被视为页面时(例如,通过使用其永久链接URL,/ landing-page /),landingpage.php将使用您定义的自定义模板().
但是,如果将同一页面作为首页访问,则使用静态首页的模板,并调用该页面front-page.php(如果存在).
删除您的front-page.php模板,或修改它以模仿您想要的行为landingpage.php.
对此的推论是,对于静态首页,如果您有模板,则无需指定特定的自定义front-page.php模板.您可以使用任何页面,该模板将适用.