且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

while 循环中的 foreach 循环

更新时间:2022-04-13 15:46:39

我会做这样的事情(使用数组而不是那个,然后使用内爆得到它之间有空格:)

i Would do something like this (use a array instead of that and then use implode to get it with spaces between it :)

<?php while ($query->have_posts()) : $query->the_post(); 

$tags = array(); // a array for the tags :)
$posttags = get_the_tags();
if (!empty($posttags)) {
  foreach($posttags as $tag) {
    $thetags =  $tag->name . ''; 
    echo $the_tags;

    $thetags = strtolower($thetags);


    $thetags = str_replace(' ','-',$thetags);
    $tags[] = $thetags;

    echo $thetags;


  }
}
?>

<!-- Loop posts -->      
<li class="item <?= implode(" ", $tags) ?>" id="<?php the_ID(); ?>" data-permalink="<?php the_permalink(); ?>">