2010-07-07 90 views
1

我做了以下在我的主页上显示一个帖子:如何让wordpress仅在评论和评论表单的首页显示一篇文章?

home.php:

<?php 
get_header(); 
query_posts('posts_per_page=1'); //returns only the front page 
?> 

<div id="content"> 
    <?php 
    /* Run the loop to output the posts. 
    * If you want to overload this in a child theme then include a file 
    * called loop-index.php and that will be used instead. 
    */ 
    get_template_part('loop', 'index'); 
    ?> 
</div> 
<div id="sidebar"> 
    <?php get_sidebar(); ?> 
</div> 
<div id="footer"> 
<?php get_footer(); ?> 

但我还是ahave点击Comments才能看到的评论和形式发表评论。我如何自动显示?

回答

1

使用<?php comments_template(); ?>加载评论模板 - 将显示当前帖子的所有评论。

+0

对不起,我将该代码放在#content div之前,什么都没发生! – alexchenco 2010-07-07 09:55:56

+0

如果要在加载循环之前显示注释,请调用'the_post()',加载注释,然后使用'rewind_posts()'重置循环。 – TheDeadMedic 2010-07-07 11:03:03

0
<?php get_header(); ?> 
    <div class="blog"> 
     <section> 
      <div class="container"> 
       <div class="row"> 
        <div class="blog-sidebar"> 
         <?php get_sidebar(); ?> 
        </div> 
        <div class="span8"> 
        <?php $articles = new WP_Query(array(
             'post_type' => 'post', 
             'post_status' => 'publish', 
             'posts_per_page' => 1 
            ));?> 
         <?php while ($articles->have_posts()): $articles->the_post(); ?> 
          <article id="post-<?php the_ID(); ?>" role="article"> 
           <header> 
            <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('wpbs-featured'); ?></a> 
           <section class="post_content clearfix" > 
            <?php the_content(); ?> 
           </section> 
          </article> 
         <?php endwhile; ?> 
         <?php comments_template('',true); ?> 
        </div> 
       </div> 
      </div> 
     </section> 
    </div> 

    <?php get_footer(); ?>