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条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献