single.php仅显示the_content()

时间:2018-08-13 13:26:06

标签: php html wordpress

我目前正在学习如何将html页面转换为wordpress并尝试创建single.php页面。问题是该页面仅显示the_content();。当我有很多其他的html和其他wordpress函数时,为什么只有get_content();才可以。页面上只显示一个吗? :

<?php get_header(); ?>

<!-- Page Header -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<header class="masthead" style="background-image: url('<?php echo get_template_directory_uri(); ?>/img/post-bg.jpg')">
  <div class="overlay"></div>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-md-10 mx-auto">
        <div class="post-heading">
          <h1><?php the_title(); ?></h1>
          <h2 class="subheading">Problems look mighty small from 150 miles up</h2>
          <span class="meta">Posted by <?php the_author_posts_link(); ?> on <?php the_time('F j, Y g:i a'); ?></span>
        </div>
      </div>
    </div>
  </div>
</header>

<!-- Post Content -->
<article>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-md-10 mx-auto">
        <?php echo "Test echo to see if I get that on the output" ?>
        <?php the_content(); ?>
      </div>
    </div>
  </div>
</article>
<?php endwhile; endif; ?>

<?php get_footer(); ?>

我得到的输出是:

<!-- Nav end -->
</nav>
<!-- single.php content -->
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.</p>

<hr>

<!-- Footer -->
<footer>

<!-- Footer -->显示footer.php的起始位置,而<!-- Nav end -->显示header.php的终止位置

预先感谢

1 个答案:

答案 0 :(得分:0)

删除标头HTML标头代码,应将其添加到header.php文件中

并在single.php中添加以下代码

<?php get_header(); ?>

<!-- Page Header -->

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Post Content -->
<article>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-md-10 mx-auto">
        <?php echo "Test echo to see if I get that on the output" ?>
        <?php the_content(); ?>
      </div>
    </div>
  </div>
</article>
<?php endwhile; endif; ?>

<?php get_footer(); ?>