Wordpress的the_title函数不起作用

时间:2017-04-29 08:35:15

标签: wordpress

我将一个HTML页面转换为wordpress但我似乎无法获得每个部分的标题以返回正确的vaule。

此代码为page.php,显示一页:

<?php
  // Template Name: One Page Layout
  get_header();
?>

<?php

  // Main Loop
  if ( have_posts() ) : while ( have_posts() ) : the_post();

  // GET HEADER
  get_template_part( 'front-header');

  // PROMOTION SECTION
  get_template_part( 'front');

  // LATEST WORK
  get_template_part( 'lwork');

  // LATEST POSTS
  get_template_part( 'lpost');

  // ABOUT ME
  get_template_part( 'about');

  // CONTACT
  get_template_part( 'contact');

  endwhile; endif; wp_reset_query();

  get_footer();
?>

这是我想要展示的标题(lpost.php):

<!-- section heading -->
<section class="section-heading">
 <h2><?php the_title(); ?></h2>
  <?php the_content(); ?>
 </section>

我错过了什么?

3 个答案:

答案 0 :(得分:0)

您需要将循环放在

部分之上
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<section class="section-heading">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</section>

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

答案 1 :(得分:0)

您的代码应为:

<?php
  query_posts(array('post_type' => 'post'));
  // Main Loop
  if ( have_posts() ) : while ( have_posts() ) : the_post();

答案 2 :(得分:0)

你可以使用这段代码:get_title()

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<section class="section-heading">
<h2><?php get_title(); ?></h2>
<?php the_content(); ?>
</section>

<?php endwhile; endif; wp_reset_query(); ?>
相关问题