dongsanhu4784 2017-02-23 13:49
浏览 127
已采纳

静态首页的自定义模板未显示 - Wordpress

I'm trying to set a custom static front page for my Wordpress, with a custom template.

I create landingpage.php in wp-content/themes/my_theme and I create a new page in my wordpress admin with LandingPage model selected.

If I go to my_website.com/landing-page/ my custom page works and 'Hello World!' appears, but if I set my custom page as a static front page and go to my_website.com/ my 'Hello World!' message doesn't display.

My landingpage.php code:

<?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();

Any idea? thx

  • 写回答

2条回答 默认 最新

  • doushijiao0679 2017-02-23 14:36
    关注

    front-page.php has precedence over your custom template.

    When that post is viewed as a page (e.g. by using its permalink url, /landing-page/), the custom template you defined (landingpage.php) will be used.

    But if the same page is accessed as a front-page, the template for static front page is used, and that one is called front-page.php (if it exists).

    Either delete your front-page.php template, or modify it so it mimics the behavior your wanted in landingpage.php.

    The corollary for this is that for a static front page, you don't need to assign a specific custom template if you have a front-page.php template. You can use any page whatsoever, and that template will apply.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复