wordpress - foreach only once -
i'm using metabox plugin wordpress, there 1 php command:
<?php $images = rwmb_meta( 'pw_project_photos', array('type'=>'plupload_image','size'=>'thumbnail') ); foreach ( $images $image ) { echo "<img src='{$image['url']}' alt='{$image['alt']}' />"; } ?>
what want to echo once, possbile?
for example, have upload 2 images 1 post, want show first image, not 2 images.
plz help me, thx lot!
you don't need loop through array if want echo 1 item.
simply do:
<?php if ( isset( $images[0] ) ) { $image = $images[0]; echo "<img src='{$image['url']}' alt='{$image['alt']}' />"; } ?>
wordpress foreach
No comments:
Post a Comment