Put this in the template file at the beginning or in functions.php file:
function get_images_attachment_url()
{
global $post;
$images_urls = array();
$images_objects = get_attached_media( 'image', $post->ID );
foreach ($images_objects as $image_object) {
$images_urls[] = wp_get_attachment_url ($image_object->ID);
}
return $images_urls;
}
When you need to call them use foreach after calling the function get_images_attachment_url():
$my_images_urls = get_images_attachment_url();
foreach ($my_images_urls as $url) {
?>
<div style="background-image: url('<?php echo $url ?>')"></div>
<?php
}
Related Posts:
- Cannot display or echo alt text on featured image
- Only show first image in foreach loop
- what’s the syntax for if the image exists get the image?
- Retrieving specific images from Media Library
- How to get URL of current page displayed?
- How to register images uploaded via FTP in media library?
- Debugging upload problem: What part of WP does actual image-resizing?
- Display only text to WordPress loop without loosing the text formatting
- Loop through child images of a parent for a Nivo Slider
- How to upload imagick resource to media in wordpress
- How to change post count in wordpress loop?
- How can I loop into two different DIVS without repeating the DIVs
- WordPress loop specific thumbnail size
- get understrap pagination to work with custom query
- How do I get images (with a thumbnail preview) to show in search results?
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- Assign a picture URL to a page via PHP
- How to scale image with equal width and height without distortion?
- Way to display “Yesterday”, “Today”
- How can i display post loop in table format?
- Get most recent media upload
- Convert all images to PNG on file upload
- multiple if statements [closed]
- Escape post image attachments added to template
- How to select WooCommerce products by post_meta and order them
- Display post image with fancybox
- have_posts() execution failure
- Echo URL of large version of Featured Image
- How does the ternary operator work in the wordpress loop post?
- Get different images for mobile and desktop with php, advanced custom fields without using js and ajax
- Using Advanced Custom Fields to create a per page slider
- WordPress Search Results for Multiple Post Types
- Using loop pagination on single.php
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- Why my image upload button is not working in wordpress widget area?
- Display category name only once inside loop
- Can’t find infinite loop cause
- WordPress function when file is uploaded, deleted or edited
- Changing the_posts_navigation() html output
- WP_Query fails despite having 1 post
- Download images from media library to computer in BULK?
- Three Questions with Twenty Eleven theme
- Loop stopped working
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Division by zero error in image.php
- How to add div blocks after certain set of post
- Why in my theme I can’t see all the statics content under the posts?
- How do I remove a category from a wordpress loop>
- Upload non-featured image to image field
- How to unlink all posts from tracking same amount of views
- WordPress loop by meta key that is an array? and how loop multiple arrays
- I’m unable to call img path using single quotes in an array?
- Get the id of all images in a post
- How to print redux gallery feilds id? [closed]
- Else/If Statement to Display Photo Descriptions
- WordPress İmages Upload & Delete Error
- Echo array value
- First post article different on Archives template
- How to add title attribute to archive items
- Attaching images to posts manually (i.e. with custom code, without the use of an API)
- Strip from or something better?
- How to break up php code to avoid echo
- How to internationalize header image?
- WordPress api post image raw data without being blank in media library
- Products listing check if meta checkbox is checked
- in_array not working on dev server but works on localhost
- Get title of page containing post grid within the posts
- Is there anyway I can call the year once?
- How do I stop an Image Address from loading in the Browser?
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- How to add a PHP scripts into WordPress
- cURL needing to loop through all “next_page”
- Display page content in different sections – based on page break block?
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- How can I get my pagination loop to display the correct number of total pages?
- How do if all posts has this category ID then do this
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- View tag description on page
- Get current_post in reverse order with pagination
- Insert div after every three posts in home.php [duplicate]
- Display product attributes for current product
- Div Missing In Custom Loop Query
- Using page template to fetch posts in page
- How to have post count after each listed category
- How can I put a custom field as the link of a button shortcode?
- Transient Loop Not working as expected
- Snapshot Theme from WooThemes — empty ‘alt’ attribute
- Custom Meta Box If Else Statement
- Conditional in foreach loop is outputting content twice
- Alternative loop syntax error [closed]
- is there away to hide php code in wordpress not to show in PAGES
- HTML in PHP problem [closed]
- Woocommerce linking variations
- Remove default Image Sizes
- I want to show image from custom field image on my custom page template
- How Create Automatically Image jpg.webp from image .jpg without delete or change original images upload
- How can add alt tag in following code. Image are showing dynamic in wordpress
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress