循环中的第二个循环把帖子搞砸了


Second loop inside The Loop messing up the post

在我的Wordpress文章页面中,我添加了第二个显示相关文章的循环。这个循环在显示文章内容的主循环中。问题是,添加第二个循环会打乱页面上的所有内容。

评论来自不同的帖子,做出新的评论会让你跳到不同的页面,等等

显然,我没有在主循环中正确插入第二个循环。

这是我的代码:

<div id="entries">
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <div class="entry post postpage clearfix">
            <?php if (get_option('aggregate_integration_single_top') <> '' && get_option('aggregate_integrate_singletop_enable') == 'on') echo(get_option('aggregate_integration_single_top')); ?>
            <h1 class="title"><?php the_title(); ?></h1>
            <?php get_template_part('includes/postinfo','single'); ?>
            <?php the_content(); ?>

<!-- START SECOND LOOP -->
<div class="radarcont">
<?php
$category = get_the_category();
$current_category = $category[0]->term_id;
$qarr = array(
    'showposts' => '4',
    'cat' => $current_category,
    'tag' => 'pinned', // filtered tag
    'post__not_in' => array(get_the_ID())
);
$q = new WP_Query($qarr);
if($q->have_posts()) : while ($q->have_posts()) : $q->the_post();
    ?>
<div class="singleradar clearfix">
    <?php
    $thumb = '';
    $width = 130;
    $height = 75;
    $classtext = 'post-image';
    $titletext = get_the_title();
    $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Recent');
    $thumb = $thumbnail["thumb"];
    ?>
    <?php if($thumb <> '' && get_option('aggregate_thumbnails_index') == 'on') { ?>
    <div class="thumb">
        <a href="<?php the_permalink(); ?>">
            <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
            <span class="overlaymed"></span>
        </a>
    </div>  <!-- end .post-thumbnail -->
    <?php } ?>
    <h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div> <!-- end .block-post -->
<?php endwhile; endif;?>
</div> <!-- end .radarcont -->
<!-- END SECOND LOOP -->

        </div> <!-- end .entry -->          
        <?php if (get_option('aggregate_show_postcomments') == 'on') comments_template('', true); ?>
    <?php endwhile; // end of the loop. ?>

如何解决此问题我怎样才能调整第二个循环,使它不会打乱其余的循环?

循环通过第二个循环后,您必须使用重置您的日志数据

wp_reset_postdata();

更多信息:http://codex.wordpress.org/Function_Reference/wp_reset_postdata