Use below code
<?php
$isFirst = true;
$i=1;
foreach ( $attachments as $attachment ):
$description = $attachment->post_content;
if($i==1)
{
echo '<div class="item'.$isFirst.'" data-description="' . $description . '">';
echo wp_get_attachment_image($attachment->ID, 'large');
echo '</div>';
}
else
{
echo '<div class="item" data-description="' . $description . '">';
echo wp_get_attachment_image($attachment->ID, 'large');
echo '</div>';
}
$i++;
endforeach;
?>
Related Posts:
- Endless loop with wp_insert_post and wp_update_post
- Add Incrementing ID to each paragraph in the_content
- post__in – Placing content from a foreach loop inside of an array
- In a foreach loop, how do I target the last item in the loop?
- How to iterate through database until it find a match
- How do I get row padding in a post feed?
- Split loop to load WordPress gallery into Bootstrap modal and carousel
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- How to print out menu names in the foreach loop?
- How do I style the first two posts of a loop
- Get Page content to displayin Bootstrap Modal
- Add class to last 3 posts in loop
- How to create bootstrap grid loop?
- Output meta into arrays
- While loop with bootstrap [closed]
- Foreach displays from last to first
- Simple foreach loop help needed in wordpress “the loop”
- How to print redux gallery feilds id? [closed]
- Posts are not looping through correctly
- How to check all items in a loop have post thumbnail?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- How to Create Carousel Indicators in PHP Loop using wp_get_attachment_url function?
- Loop two different category WP_Query
- Bootstrap tabs are not being clicked in WordPress loop
- I want to load post in bootstrap Modal dynamically
- Problems with the WordPress loop [closed]
- Retrieving specific images from Media Library
- Get featured image outside the loop using foreach
- Why loop renders only last metabox from array? [closed]
- Foundation modal in wordpress php loop
- ACF field not appearing correctly in loop
- How to display thumbnail if post is assigned one otherwise not
- Twitter bootstrap carousel multiple items in carousel
- How to create WordPress loop with combination of 4 and 2 columns twitter-bootstrap?
- Eliminate duplicates in a foreach loop [closed]
- Wrap every 2 divs in row – for each loop [closed]
- ACF loops false value with repeater and checkbox
- Obtain page data and use regular loop
- How to display posts by vote count and if no value continue with latest posts with no votes?
- How can I load posts starting from, and including, the current post?
- Load wordpress content in other domain
- Genesis multiple category custom loop 404s after first page
- Custom Loop Using Shortcode in Custom Page Template
- Do I need to use The Loop on pages?
- Sort results by groups of numbers and letters
- Listing subpages title and content and styling the first iteration differently
- Infinite Scroll on a loop?
- Shortcode in posts called by ajax is not working
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- How to fix pagination for custom loops?
- Modify the main loop to display current month / year
- Show all posts using the template page and the loop?
- Checkbox doesn’t stay checked, conten
- Using Select HTML in Bootstrap Popovers
- Showing sticky posts with get_posts()
- Pagination – works on local but not live dev!
- On single.php, fetch 2 posts created after and 2 posts created before in relation to the actual post (using menu_order)
- query_posts() vs get_posts() multiple loops [duplicate]
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- need help looping add_action in wp
- Problem getting current post tags to show in a widget
- Modified loop-single-forum.php to work inside of a sidebar Widget, not working on some site pages
- List authors with the last post title and order by last post date
- How to get the role id from the role name?
- Does WordPress Loop have a function like Shopify’s cycle?
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- Basic multiple loops only displaying first loop
- Add class to group inner container
- Using Javascript for Looped Content
- Latest Post Styled Different Than other Posts
- Display post list with different styles
- ‘Auto Draft’ Post showing in wordpress loop
- How do I display an image before the first post of the loop when I’m using get_template_part?
- ACF custom field in [closed]
- Split wordpress loop to multiple layouts
- Post classes in the loop are being changed in certain themes
- single.php – how to mark current page in the loop
- WordPress style.css not updating, only after theme reload
- Problem with displaying HTML content after in_array [closed]
- post thumbnail, conditions, else wont work
- How do I make a variable available inside partials?
- How to hook into container
- Why does `inclusive` not work in this wordpress loop?
- Combine the results of two loops [closed]
- Widgets in the loop if active
- How do I automate multiple category loops?
- Added if statement to loop
- Both a page loop and posts loop on the same page
- WordPress: Loop Help
- How to get The Loop working with $wpdb->get_results()
- List posts that don’t have a specific tag?
- Changing the_posts_navigation() html output
- Making a query to the DB using same parameters of loop
- Woocommerce: How to display product price [closed]
- How to show more random posts if Tag has less than 3 posts
- Can we count the WordPress Loop
- Variable not being passed into WordPress loop
- Is wp_reset_postdata() redundant after the main loop?
- Cannot retieve the_content() and the_author() – both returning empty strings
- Exclude duplicated $sticky post from combined loop content