Home > Article > Backend Development > Wordpress gets pictures from photo album
If you insert only one Gallery containing multiple pictures into the article, is there any way to get the pictures in the album as thumbnails?
The two methods that come to mind now have proven to be ineffective. One is to use the Auto thumbnail plug-in to obtain featured images
<code><?php $array_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(100,100)); echo $array_image_url[0]; ?></code>
After testing, it is invalid and the pictures in the album cannot be automatically set as thumbnails.
The second method is to get the first picture in the article and add it in function.php:
<code>function get_content_first_image($content){ if ( $content === false ) $content = get_the_content(); preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $content, $images); if($images){ return $images[1][0]; }else{ return false; } } </code>
Then use it wherever you need to call:
<code><img src="<?php echo get_content_first_image(get_the_content()); ?>"/> </code>
After testing, the pictures in the album cannot be obtained.
The wordpress photo album is inserted via the shortcode [gallery id = "..."].
Is there any way to get the address of the image attachment in the album?
If you insert only one Gallery containing multiple pictures into the article, is there any way to get the pictures in the album as thumbnails?
The two methods that come to mind now have proven to be ineffective. One is to use the Auto thumbnail plug-in to obtain featured images
<code><?php $array_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(100,100)); echo $array_image_url[0]; ?></code>
After testing, it is invalid and the pictures in the album cannot be automatically set as thumbnails.
The second method is to get the first picture in the article and add it in function.php:
<code>function get_content_first_image($content){ if ( $content === false ) $content = get_the_content(); preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $content, $images); if($images){ return $images[1][0]; }else{ return false; } } </code>
Then use it wherever you need to call:
<code><img src="<?php echo get_content_first_image(get_the_content()); ?>"/> </code>
After testing, the pictures in the album cannot be obtained.
The wordpress photo album is inserted via the shortcode [gallery id = "..."].
Is there any way to get the address of the image attachment in the album?