我使用foreach
获取图片列表,但我不想显示阵列的第一张图片,但我不知道如何使其有效。这是我的代码:
$portfolio_gallery_image = get_post_meta( get_the_ID(), "portfolio_gallery_image", true );
<div class="folio-gallery grid-masonry clearfix">
<?php
foreach ( $portfolio_gallery_image as $key => $image ){
?>
<a class="folio-item col-3 ndSvgFill grid-item" href="<?php echo esc_url($image) ?>">
<img src="<?php echo esc_attr($image) ?>" alt="portfolio">
</a>
<?php } ?>
</div>
这是数组
Array
(
[2098] => http://dione.thememove.com/wp-content/uploads/2016/04/11.jpg
[2097] => http://dione.thememove.com/wp-content/uploads/2016/04/10.jpg
[2062] => http://dione.thememove.com/wp-content/uploads/2016/06/f_08.jpg
[2084] => http://dione.thememove.com/wp-content/uploads/2016/06/10.jpg
[2096] => http://dione.thememove.com/wp-content/uploads/2016/04/9.jpg
[2082] => http://dione.thememove.com/wp-content/uploads/2016/06/08.jpg
[2094] => http://dione.thememove.com/wp-content/uploads/2016/04/7.jpg
)
非常感谢您的帮助。谢谢。
答案 0 :(得分:2)
你可以这样做,
<?php
function custom_function(&$arr)
{
list($k) = array_keys($arr);
$r = array($k => $arr[$k]);
unset($arr[$k]);
return $r;
}
custom_function($portfolio_gallery_image);
foreach ($portfolio_gallery_image as $key => $image) {
?>
<a class="folio-item col-3 ndSvgFill grid-item" href="<?php echo esc_url($image) ?>">
<img src="<?php echo esc_attr($image) ?>" alt="portfolio">
</a>
<?php } ?>
array_shift从数组的开头移出一个元素。
答案 1 :(得分:0)
尝试使用以下代码从代码中删除第一个键/值,然后再为代码中的每一个删除。
$new_image_array = array_shift($portfolio_gallery_image);