wordpress自定义页面模板

wordpress自定义页面模板,wordpress,templates,loops,Wordpress,Templates,Loops,我已经创建了一个名为“产品”的自定义页面 <?php /* Template Name: Products */ ?> <?php get_header(); ?> <div id="products_content"> <div id="products_page_header"> <div id="products_page" title="محصولات"> <?php if (have_post

我已经创建了一个名为“产品”的自定义页面

<?php
/*
 Template Name: Products
*/
?>
<?php get_header(); ?>

<div id="products_content">
  <div id="products_page_header">
    <div id="products_page" title="محصولات">
      <?php if (have_posts()) : while (have_posts()) : the_post();?>
      <div class="post">
        <h2 id="post-<?php the_ID(); ?>">
          <?php the_title();?>
        </h2>
        <div class="entrytext">
          <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
        </div>
      </div>
      <?php endwhile; endif; ?>
    </div>
  </div>
</div>
<div id="clear"> </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body></html>


但是它没有显示我的帖子,我做错了什么?

对于标准的wordpress循环,这应该是

<?php endwhile; ?>
<?php else : ?>

(optional: Sorry, but you are looking for something that isn't here.)

<?php endif; ?>

<?php get_sidebar(); ?>
<?php get_footer();?>

(可选:抱歉,您正在查找不在此处的内容。)

此代码不像博客页面那样显示您的帖子,此代码仅显示页面“产品”的内容,若要显示您的所有帖子,必须使用其他代码:

<?php
/*
 Template Name: Products
*/
?>
<?php get_header(); ?>

<div id="products_content">
  <div id="products_page_header">
    <div id="products_page" title="محصولات">
      <?php $query = new WP_Query('showposts=10'.'&paged='.$paged); ?>
            <?php if ($query->have_posts()) : ?>
        <?php while ($query->have_posts()) : $query->the_post(); ?>
      <div class="post">
        <h2 id="post-<?php the_ID(); ?>">
          <?php the_title();?>
        </h2>
        <div class="entrytext">
          <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
        </div>
      </div>
      <?php endwhile; endif; ?>
    </div>
  </div>
</div>
<div id="clear"> </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body></html>