I am creating a new page on wordpress and adding images using php code.
This is the code I have so far, which gives me the src url in an array. However i think this gives me all the images in the gallery. is there a way to find just the images on the page and then add these images to the page. See my current code below.
<?php
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image ) {
echo wp_get_attachment_url( $image->ID );
}
?>
尝试这个
echo "<img src='".wp_get_attachment_url( $image->ID )."' />";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.