猿问

向子元素添加订单号,1,2,3,4,5

我正在尝试将订单号输出到从图库标题生成的元素。


foreach ( $item['gallery'] as $image ) {

  $lines = intval( apply_filters( 'caption_line', 1 ) );

  for ( $line = 1; $line <= $lines; $line++ ) {

    $attachment_post = get_post( $image['id'] );

    $image_caption = $attachment_post->post_excerpt;

    echo '<span class="dot1" onclick="currentSlide' . $item['unit_link'] . '(' . esc_attr( $line ) . ')">' . $image_caption . '</span>';

    }

}

所以我需要为$line生成1,2,3,4...,但是对于我尝试过的东西,它只为所有元素输出1,更改1$lines= intval(apply_filters(“caption_line”,1));到较大的数字显示数字,但也复制它们。


达令说
浏览 106回答 1
1回答

犯罪嫌疑人X

只是想通了,这正是我一直在寻找的!foreach ( $item['gallery'] as $key => $image ) {&nbsp; $attachment_post = get_post( $image['id'] );&nbsp; $image_caption = $attachment_post->post_excerpt;&nbsp; $keyplus = $key+1;&nbsp; &nbsp; &nbsp;echo '<span class="dot1" onclick="currentSlide' . $item['unit_link'] . '(' .&nbsp; $keyplus . ')">' . $image_caption . '</span>';}
随时随地看视频慕课网APP
我要回答