Gar*_*ods 0 php wordpress post loops
在我的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. ?>
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?如何调整第二个循环以使其不会弄乱其余部分?
小智 5
循环完第二个循环后,您必须重置帖子数据:
wp_reset_postdata();
Run Code Online (Sandbox Code Playgroud)
更多信息:http://codex.wordpress.org/Function_Reference/wp_reset_postdata
| 归档时间: |
|
| 查看次数: |
203 次 |
| 最近记录: |