While循环无法正常工作
问题描述:
我试图表现出一定的相关信息,我想只有一次创建一个div,之后只显示内容While循环无法正常工作
<?php while ($loop1->have_posts()) : $loop1->the_post(); ?>
<?php if($cnt == 0): echo "<div class=\"big-image\">";endif; ?>
<img src="<?php echo get_post_meta(get_the_ID(),'details_artists_image',true);?>" height="414" width="810" style="display:none"/>
<?php if($cnt ==0): echo "</div><!--end big-image--><ul class=\"artiesten-thumbs clearfix\">";endif; ?>
<li>
<a href="<?php echo get_post_meta(get_the_ID(),'details_artists_image',true);?>"><img width="99" height="99" src="<?php echo get_post_meta(get_the_ID(),'details_artists_image',true);?>" alt=""></a>
<span><?php the_title(); ?></span>
</li>
<?php $cnt++; endwhile; ?>
</ul>
的问题是,输出看起来像这样:
<div class="big-image"><img src="url" ... /></div>
<ul class="artiesten-thumbs">
<li>
<a href="url"><img width="99" height="99" src="url" alt=""></a>
<span>LP & BRUGE</span>
</li>
<img again that should be in <div class="big-image"
<li>
<a href="url"><img width="99" height="99" src="url" alt=""></a>
<span>LP & BRUGE</span>
</li>
<img again that should be in <div class="big-image"
所以也没有表明应该在div的图像,它显示了他们一个接一个,每个<li>
答
后,您是在每次打印出的图像关合作。你想要这样的东西
<?php if($cnt == 0) : ?>
<div class="big-image">
<img src="<?php echo get_post_meta(get_the_ID(),'details_artists_image',true);?>" height="414" width="810" style="display:none"/>
</div><!--end big-image-->
<ul class="artiesten-thumbs clearfix">
<?php endif; ?>
哇这真是令人困惑,但我认为你想要做的是运行while循环两次,一次为图像,一次为内容。或者只是将html字符串分隔成2个变量,而在循环中使用一个用于图像,另一个用于内容。希望这可以帮助 – mseancole 2012-03-21 21:48:16