我有一个问题,从早上起我无法解决。
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
这是index.php中的wordpress the loop
。当我添加the_post
时,页面中的最后一个帖子消失,当我删除它时,所有帖子都会混淆。
你能帮我解决一下。
这是完整的index.php
<?php get_header(); ?>
<div id="body">
<div class="content-container">
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="content-whole">
<div class="thumbnail">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<div class="content">
<div class="post-title">
<p class="postmetadata">
Posted<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';?>
with <a href="#disqus_thread"><?php the_post(); comments_number(); ?></a>
<?php } ?>
</p>
<h2 id="post-title">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php
$cats=get_the_category();
echo $cats[0]->cat_name;
?> : <?php the_title(); ?></a></h2>
</div>
<?php the_content('Read More »'); ?>
</div><!--end content-->
</div><!--end content whole-->
<?php endwhile; ?>
<div class="pagenavi">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
</div>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
答案 0 :(得分:0)
你展示的不是一个完整的循环;你错过了其余的逻辑,即endwhile
和endif
陈述。
这是来自http://codex.wordpress.org/The_Loop_in_Action
的最基本的Wordpress循环<?php
get_header();
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;
get_sidebar();
get_footer();
?>
阅读该链接的文档,了解如何修复循环并构建不同的Wordpress循环。
答案 1 :(得分:0)
完成后我删除了the_post();从
<a href="#disqus_thread"><?php the_post(); comments_number(); ?></a>