" height="414" -6ren">
gpt4 book ai didi

php - 虽然循环无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-04 16:00:56 25 4
gpt4 key购买 nike

我想显示一些信息,我只想创建一个 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> 之后一张一张地显示它们。

最佳答案

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

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

关于php - 虽然循环无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com