我执行了以下操作以在我的主页中显示单个帖子:
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
才能看到评论和表单以发表评论。如何立即自动显示?
答案 0 :(得分:1)
使用<?php comments_template(); ?>
加载评论模板 - 这将显示当前帖子的所有评论。
答案 1 :(得分: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(); ?>