20分求助PHP循环问题!
这段代码运行正常,但是 <div class="body_fenlei_beijing"></div> 这个标签一直无限循环!各位大神帮忙看看是不是代码写错了!
<?php get_header(); ?>
<div id="container">
<div id="main">
<?php if ( function_exists('show_nivo_slider') ) { show_nivo_slider(); } ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
// 得到所有分类列表
$categories = get_categories();
// 循环所有分类
foreach ($categories as $cat) {
// 得到分类ID
$catid = $cat->cat_ID;
// 得到分类下10篇最新文章
query_posts("showposts=10&cat=$catid"); ?>
<div class="body_fenlei_beijing">
<div class="body_fenlei_kongbai"></div>
<!– 输出分类标题及链接 –>
<div class="body_fenlei_title">
<h4><a href=”<?php echo get_category_link($catid);?>”
title=”<?php echo strip_tags(category_description($catid)); ?>”>
<?php single_cat_title(); ?>
</a></h4>
</div>
<!– 输出10篇最新文章的标题及链接 –>
<div class="body_fenlei_link">
<?php while (have_posts()) : the_post(); ?>
<li>
<a href=”<?php the_permalink() ?>” title=”<?php the_title(); ?>”>
<?php the_title(); ?></a>
<?php the_time(‘m-d’); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php } ?><!-- end .post -->
<?php endwhile; ?>
<?php else : ?>
<div class="post not-found">
<div class="title">
<h2><?php _e("Not Found", "ultimo"); ?></h2>
</div>
<div class="clear"></div>
<div class="entry no-result">
<p class="no_result"><?php _e("Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.", "ultimo"); ?></p>
</div>
</div><!-- end .post -->
<?php endif; ?>
<?php if(function_exists('wp_pagenavi')) : ?>
<div class="pagenavi">
<?php wp_pagenavi(); ?>
</div>
<?php else : ?>
<div class="pagination" style="display: none;">
<span class="left"><?php next_posts_link(__("« Prev Page", "ultimo")); //next_posts_link points to older posts ?></span>
<span class="right"><?php previous_posts_link(__("Next Page »", "ultimo"));//previous_posts_link points to newer posts ?></span>
<div class="clear"></div>
</div><!-- end .pagination -->
<?php endif; ?>
</div><!-- end #main -->
<?php get_sidebar(); ?>
<div class="clear"></div>
</div><!-- end #container -->
<div class="clear"></div><!--ie6-->
<?php get_footer(); ?>
追问:哪个部分放到循环外?有没有办法让他 循环读取完所有分类之后 再结束
其他:如果楼上的解决了,我就不插手了 呵呵 是不是你 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>里面嵌套了
<?php while (have_posts()) : the_post(); ?>
也许你要在被 嵌套的那个have_posts前调用一下 rewind_posts();
参考官方API说明:http://codex.wordpress.org/The_Loop#Multiple_Loops
上一个:新手php程序员问个事
下一个:着急,php毕业设计中留言板登录权限SESSION问题!