虽然循环不能正常工作

时间:2012-03-21 21:39:09

标签: php html css wordpress

我正在尝试显示一些信息,我想只创建一次div,之后只显示内容

<?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 &#038; 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 &#038; BRUGE</span>
</li>
<img again that should be in <div class="big-image"

所以它没有显示应该在div中的图像,它会在每个<li>之后逐个显示它们

1 个答案:

答案 0 :(得分:1)

您正在每次迭代时打印出图像。你想要这样的东西

<?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; ?>