2012-03-21 157 views
0

我試圖表現出一定的相關信息,我想只有一次創建一個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 &#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>

+0

哇這真是令人困惑,但我認爲你想要做的是運行while循環兩次,一次爲圖像,一次爲內容。或者只是將html字符串分隔成2個變量,而在循環中使用一個用於圖像,另一個用於內容。希望這可以幫助 – mseancole 2012-03-21 21:48:16

回答

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