Как заставить Wordpress показывать только один пост на первой странице с комментариями и формой комментариев? - PullRequest
1 голос
/ 07 июля 2010

Я сделал следующее, чтобы отобразить одно сообщение на моей домашней странице:

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

Но я все еще должен нажать Comments для того, чтобы увидеть комментарии и форму, чтобы оставить комментарий.Как я могу автоматически показать сразу?

Ответы [ 2 ]

1 голос
/ 07 июля 2010

Загрузите шаблон комментариев, используя <?php comments_template(); ?> - это отобразит все комментарии для текущего сообщения.

0 голосов
/ 21 апреля 2015
    <?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(); ?>
...