在WordPress中创建自定义模板页面,导致其他功能停止工作


Creating a custom template page in wordpress causing other features to stop working

我是wordpress的新手,我正在尝试创建自定义模板。我使用的是默认的十二五主题。我去wp-content/themes/twentyfifteen page.php复制到一个名为page_with-contact.php的新文件中,并在顶部添加了以下评论:

/*
Template Name: Page with contact
*/

我没有对模板进行任何其他更改。然后我去了管理网站,将其中一个页面更改为"有联系人的页面"。

当我打开页面时,我看到左侧菜单上的词缀不起作用,响应式菜单也不起作用。

在这里遵循了一个非常简单的教程,所以我只是想知道我做错了什么。

编辑

按照@masiorama的回答和下面的评论被装箱为子主题,将模板文件移动到子主题并重命名为page-with-contact.php,这就是模板的内容

<?php
/*
Template Name: Page with contact
*/
get_header(); ?>
  <div id="primary" class="content-area">
    <main id="main" class="site-main my-content-page" role="main">
    <?php
    // Start the loop.
    while ( have_posts() ) : the_post();
      // Include the page content template.
      get_template_part( 'content', 'page' );
      // If comments are open or we have at least one comment, load up the comment template.
    ?>
      <div class="hentry entry-content contact-form">
        <?php
          echo do_shortcode('[contact-form-7 id="19" title="contact form 1"]');
        ?>
      </div>
    <?php
    // End the loop.
    endwhile;
    ?>
    </main><!-- .site-main -->
  </div><!-- .content-area -->
<?php
  get_sidebar();
  get_footer();
?>

现在我有几个问题:

  1. 如您所见,侧边栏,标题和页脚都包括在内,但附加词缀和响应菜单仍然不起作用。

  2. 联系表单(以前工作正常)现在根本不显示。

  3. 我无法将父文件的rtl.css文件排队。

感谢任何进一步的指导。

据我所知,您的页面文件应该命名:

page-with-contact.php

而不是:

page_with-contact.php

确保它至少包含一些wordpress函数调用,例如:

<?php get_header(); ?>
<!-- stuff -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

查看此内容以获取更多详细信息:http://codex.wordpress.org/Page_Templates

看起来您正在调用模板中的模板。"get_template_part( 'content', 'page' );"应为the_content();。很有可能这就是让你胡闹的原因。

需要这个WordPress钩子来调用你的模板

   
get_header();
get_sidebar();
get_footer();