<?php
$x = 1;
while($x <= 17) {
switch($x) {
case 1: $sdg_text = "End poverty in all its forms everywhere";
case 2: $sdg_text = 'End hunger, achieve food security and improved nutrition and promote sustainable agriculture';
case 3: $sdg_text = "Ensure healthy lives and promote well-being for all at all ages";
default: echo '';
}
?>
<div class='grid-20 mobile-grid-100'>
<ul class="img-list">
<li>
<a>
<img src="<?php echo get_template_directory_uri(); ?>/img/sdg/sdg<?php echo $x?>.svg" />
<span class="text-content"><span><?php echo $sdg_text; ?></span></span>
</a>
</li>
</ul>
</div>
<?php $x++ ?>
<?php } //End of While ?>
我现在有一组列为SDG1,SDG2 ... SDG17图像的每个图像将有你悬停文字。我正在复制sustainable development in the UN website.
而不是一遍又一遍地复制div,我认为将它放在while循环中并在while循环中,有一个开关循环,可以根据大小写回显文本。现在,它只会回显默认值。
预先感谢您。
手册php - > switch case。你忘了关于“break”的情况下 – nospor