开发者

wordpress custom page template

I开发者_如何学Python have created a custom page named 'products'

<?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>

but it doesnt show my posts, what am I doing wrong ?


This Code doenst shows your Posts like an Blog Page, this Code shows only the Content of the Page "Products", to show all your Posts, you must use another code:

<?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>


For a standard wordpress loop, this <?php endwhile; endif; ?> should be

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

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

<?php endif; ?>

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜