first, read this about query_posts
.
to answer your question-
has_post_thumbnail()
returns true or false, iterating over that in a foreach loop isn’t possible.
I’ll guess that the reason why the same modal appears to be repeated is that you’re giving them all the same id, so the first one is always opened. Use the post’s ID to make those unique to each post.
if (has_post_thumbnail() ) {
echo '<li><a href="#" class="photo" data-reveal-id="myModal' . get_the_ID() . '"></a></li>';
echo '<div id="myModal' . get_the_ID() . '">' . get_the_post_thumbnail() . '</div>';
}
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
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- How to print out menu names in the foreach loop?
- Add class to last 3 posts in loop
- Output meta into arrays
- Need to add class to first element in a foreach loop
- Foreach displays from last to first
- Simple foreach loop help needed in wordpress “the loop”
- How to print redux gallery feilds id? [closed]
- How to check all items in a loop have post thumbnail?
- Get featured image outside the loop using foreach
- Why loop renders only last metabox from array? [closed]
- ACF field not appearing correctly in loop
- 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
- Post classes in the loop are being changed in certain themes
- single.php – how to mark current page in the loop
- 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
- Get post id within comments loop
- Exclude first post (sticky or not) from the loop using query_posts()
- How to order by multiple fields using standard query_posts?
- Multiple get_posts() queries on one page
- Loop for sticky posts
- Update status of all posts in a category
- Getting a custom field in the middle of a loop
- Syntax error when I try to insert my loop into an unordered list? [closed]
- WP_Query fails despite having 1 post
- Including all post id’s of a custom post type into an array
- Pagination on Single Post
- is_active-sidebar loop
- How to add a specific div element to the first post in a row?
- Get author_id in wordpress
- Single.php different behaviour from admin to non-admin
- Get 1 more post in loop
- Unable to change the “Read more” text inside the_excerpt
- Exclude page name from loop
- How to display pending posts on the homepage only for editors
- PHP if post is already displayed, then
- How to style first post differently with ‘get_template_part’?
- Display Posts Only with Specific Tag
- How to get my loop to paginate?
- Pagination not working in category listing [duplicate]
- Display Post Author Link above the loop
- How can I improve the performance of this query_posts loop?
- WordPress Blog has an infinite redirect loop
- Enabling users to control custom loop’s query
- Group posts by date with a list
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- Include multiple page ids in loop
- Add leading zero to current post display [closed]
- Change date format
- “Call to a member function have_posts() on array” error on have_posts();
- Add content after the first post in WP Loop
- wp_query get the 2nd post
- Distribute Gallery Images Every nth in Loop
- How can I group posts by months and years?
- Array ids post to function have_post
- Loop stopped working
- WordPress Image Slider Looping Title Not Working
- How to get post ID in a Page?
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Custom loop not working
- Get author Meta for particular user inside the loop
- Conditional: IF current user has NOT commented on current post (not including post author)
- Can’t access PHP array inside script localization from javascript
- in Foreach Loop the Description is not showing?
- Custom Pagination is Broken
- Display an image if odd number of posts in grid
- Loop increase number
- ACF – add a group inside a repeater [closed]
- Loop inside query
- How to loop through all the attached images in a post, and get their url one by one
- 404 Template customization | Want 10 recent Post on the 404.php error page apart from the error Notice
- How to create bootstrap grid loop?