wp_get_attachment_image()
has a fourth parameter for custom attributes. Use it:
if ( count( $images ) > 0 ) {
$i = 0;
foreach ( $images as $image ) {
echo wp_get_attachment_image(
$image->ID,
'photogallery-img',
FALSE,
array (
'class' => 'attachment-photogallery-img '
. ( ( $i++ % 2 === 0 ) ? 'even' : 'odd' )
)
);
}
}
Related Posts:
- How To Retrieve An Image Attachment’s Alt Text?
- getting attachement images src and add classes
- Check if post has attachments (not image)
- Validate alt text for attachments?
- Applying automatic link class to images embedded to posts
- get post attachments of a particular size
- Change image link: wp_get_attachment_link
- Making images from single.php pointing to an attachment .php template
- wp_get_attachment_image_src always returns false
- Exact image sizes
- Get the size (size in Kb or MB) of an featured image?
- query attachment images … if no attachments -> get attachments of parent page?
- Edit default image attachment size
- Change code to display image attachment page
- Attachment 0×0 size error [closed]
- Add image attachment to post via coding?
- Removing width and height attributes from wp-get-attachment
- Get post attachment images dimension and use in embed code
- use wp_get_attachment_image() to show attachments
- Adding width and height to wp_get_attachment_image_src
- Get the bare URL for an attachment
- Display attachment resolution size
- How to check if there is image title, caption, description?
- How to remove attachments size attribute [duplicate]
- How to redirect ‘file url’ to ‘post url’ i.e. in attachment.php
- Check what attached image size is used
- How do I get all attachments that are used in the current post, not just the children?
- Clean up images, delete unused image sizes attached to a post type
- Get title of post image is attached to
- Correct attachment size
- Post Gallery list attachments except the one used as post thumbnail
- Get image attachment to a post outside the loop?
- How do I intercept and modify the functionality of wp_get_attachment_image()?
- Unable to get wp_get_attachment_url to show
- Get Attachment Image Class by attachment id
- changing the default picture size link url
- Get an image from the media library. Struggling with the code?
- How to view exact image dimensions of a media in Admin view?
- Filter not applied to all image sizes
- wp_get_attachment_image_src calling wrong location
- Get attachment URL from attachment Link in WordPress
- Display setting ‘size’ not available in image settings modal
- Hide Image Container if No Image Attachments
- Incomplete attachment page
- How to retrieve “custom url” from image attachment in wordpress
- Retreive tags from attached post for media on page
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- get_image_tag filter not working
- Change attachment inside the_content using filters
- How to get attachment file name not attachment URL
- How to cleanly delete attachment but retain original file?
- Get all posts (of any post type) an attachment is used in
- Insert an image into a post by API
- How can I display custom fields value from attachment media?
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Separate attachment images from post loop
- Add_Filter example for wp_get_attachment_link
- How to get meta value in wp_attachment_metadata
- Can i hide the attachments from media which I uploaded from front end?
- Rename attachments during upload
- Automatically delete attachments and posts [closed]
- How to delete orphan attachments?
- Disable edit media attachments?
- Post Auto Draft Issue
- Display one random image, but only if landscape
- How to change image url?
- post_author for wp_insert_attachment
- get the image of the post
- Ordering of gallery images without using shortcode in theme
- Load post attached images on a single page site with fancybox
- Out of memory error reporting
- attachment.php code or tutorial
- Control attachments menu order with jQuery Sortable
- Link Attachment Image to Category
- Set size for attachments
- Images attached to posts from library link to 404 error page
- Custom image sizes add to metadata
- What are the meta fields for an attachment?
- has_excerpt yields true but no post_excerpt when retrieved
- Hiding or removing file extension displayed in HTML on attachment page
- After changing permalink structure, How to redirect attachment url to old parent post url
- Can’t sort get_posts by post_mime_type
- How to replace post image url before posting using api?
- How to get post id of first child of the same post type?
- How to list “invisible” Auto Drafts?
- How to add media from front-end to an existing post and edit file title
- Auto delete content in specific folder inside media library
- How to update an image attachment’s alt text from a custom field when saving a post?
- How to echo images Urls from a wordpress post, that are relally in the post
- How is it possible that a gallery doesn’t have attachment ids?
- Allow users to upload attachments to certain posts
- Media item permalink goes to source file instead of attachment.php
- How can I add an “Attach image to this post/page” link on the Add Media lightbox?
- Attachment file display link text
- Open image size links in a page instead of direct image link
- Create a custom attachment thumbnail for quick page load
- Add link to attachment for old posts
- How can I hide previous_image_link() on first attachment page?
- Change the next thumbnail to text