为什么这个PHP代码没有删除页眉和页脚?

时间:2017-04-24 22:23:25

标签: php html wordpress

此代码附带主题,它假设删除页眉和页脚但不执行此操作。我可以添加什么来使它工作?感谢

我试图将其从以下页面http://www.mobiletechrx.com/tuts3/中删除,但它似乎没有这些元素就会呈现。谢谢!

<?php
/**
 * Template Name: No Header Or Footer Page
 */
?>
<?php get_header(); ?>
<?php while (have_posts()) : the_post(); ?>


<section style="background-image: url()" class="banner alternate_page">
  <div class="container">
    <div class="main_cap">
      <div class="caption">
        <h2>
        </h2>
      </div>
    </div>
  </div>
</section>

<section class="north_america default_page_with_sidebar">
  <div class="container">
    <div class="fullwidth_part">
      <?php the_content(); ?>
    </div>
  </div>
</section>

<section class="mobiletech_built mobiletech_built_cutom">
  <div class="container">
    <div class="title_2">
      <h2></h2>

    </div>
    <ul>

    </ul>
  </div>
</section>

<?php wp_reset_query(); ?>
<?php endwhile; ?>
<?php get_footer(); ?>

2 个答案:

答案 0 :(得分:2)

您有<?php get_header(); ?><?php get_footer(); ?> - 您期望什么 - 这些标记是否包含页眉和页脚?

你可以删除它们,但你必须确保仍然保持一个完整有效的HTML页面结构 - 特别是header.php还包含许多&#34;不可见&#34;你需要的东西。

答案 1 :(得分:0)

您可以按照johannes建议分别删除<?php get_header(); ?><?php get_footer(); ?>来删除页眉和页脚。但请注意,标头中包含<head>标记,页眉和页脚中都包含<body><html>标记。

您可以执行的操作是将HTML结构从header.php复制到<body>标记并粘贴到模板文件中。页脚也是如此,在footer.php中复制您需要的HTML结构并将其粘贴到主题文件中。所以它看起来像这样:

<?php
/**
* Template Name: No Header Or Footer Page
*/
?>
<!-- This is the start of the contents copied from header.php -->
<html>
    <head>
      <!-- Some Codes from your header.php-->
      <?php wp_head();?>
      <!-- Some scripts and styles-->
    </head>
    <body>
   <!-- This is maybe the end of the contents copied from header.php -->
   <?php while (have_posts()) : the_post(); ?>
     <section style="background-image: url()" class="banner alternate_page">
       <div class="container">
         <div class="main_cap">
           <div class="caption">
            <h2>
            </h2>
           </div>
         </div>
        </div>
     </section>
     <!-- Some codes -->
     <?php wp_reset_query(); ?>
     <?php endwhile; ?>
     <!-- Some of the contents copied from the footer.php. That includes the scripts called outside the wp_footer action hook and such.-->
     <?php wp_footer();?>
   </body>
</html>