开发者

How to make Wordpress show only one post on the front page with comments, and comment form?

I did the following to display a single post in my home page:

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(); ?>

But I still ahave to click Comments in order to see the co开发者_Go百科mments and the form to leave a comment. How can I automatically show immediately?


Load the comments template using <?php comments_template(); ?> - that'll display all comments for the current post.


    <?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(); ?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜