Display Images from Array with wp_get_attachment_image() [closed]
I'd like the client to be able to type any image ID (number) from any gallery / attachment and then displaying it with wp_get_attachment_image().
Here is my code:
if ( $images ) {
foreach ( $images as $image ) {
echo '<li>';
echo wp_get_attachment_image( $images, 'thumbnail' ); // notice this part
echo '</li>';
}
When I do print_r $images, I get this array: Array ( [0] => 318 [1] => 304 [2] => 301 [3] => 299 [4] => 297 )
and it works if I hardcoding the array, like
echo wp_get_attachment_image( 304, 'thumbnail' );,
but of course I'd like it to appear dynamically.
How to do that? Thanks in advance.
I'd like the client to be able to type any image ID (number) from any gallery / attachment and then displaying it with wp_get_attachment_image().
Here is my code:
if ( $images ) {
foreach ( $images as $image ) {
echo '<li>';
echo wp_get_attachment_image( $images, 'thumbnail' ); // notice this part
echo '</li>';
}
When I do print_r $images, I get this array: Array ( [0] => 318 [1] => 304 [2] => 301 [3] => 299 [4] => 297 )
and it works if I hardcoding the array, like
echo wp_get_attachment_image( 304, 'thumbnail' );,
but of course I'd like it to appear dynamically.
How to do that? Thanks in advance.
No comments:
Post a Comment