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
- Jquery Slider for profile template
- Should I use loop in the single.php file?
- Inject post (from specific category) between posts in Loop
- Installing wp3.2.1 on IIS; getting empty sessions
- wp_list_categories: get latest featured_image of category
- Want to separate sections of posts. Can you restart loop?
- Specific Loop For 2 Within Each
- Two posts in same div – WP loop
- Woocommerce, recognize the loop of related products
- get_the_foo() in the loop – does it perform another query?
- Exclude filter on front page
- category__not_in — anyway to use category name instead of id?
- Check if date of post is yesterday
- Exclude first 2 posts with meta_key from loop
- Fix inefficient loop breaks post.php on form submit
- Output 2 items within the Loop
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Pulling current post/page data into header.php
- Loop and Page template : my WP_query don’t take args
- How can I add pagination and how can I change thumbnail size?
- How to split a loop into two columns
- Category Ajax call
- Transient loop issue
- popular post weekly and monthly
- Display post category in foreach loop with category link
- Show css depending on activity type in BuddyPress activity-loop [closed]
- WordPress Loop inside Loop?
- Get single post from tags array
- Apply an Incremental Counter in an Array Function
- Counter in loop in foreach
- Latest Post Styled Different Than other Posts
- ACF custom field in [closed]
- Woocommerce: How to display product price [closed]
- How can I group posts by months and years?
- Add “showing posts x to x of y” in custom post type paginated loop
- Echo a shortcode div after every 3 posts
- New loop vs widget
- Display a single category in blog section
- Query Nopaging action not having effect
- Pagination broken after using 2 loops to show content
- Only show first image in foreach loop
- Wpdb get->results to out the the month from the db
- Getting page slug
- How to get pagination to work with 2 wordpress loops
- Exclude page from loop results
- How is WordPress changing the content markup?
- Inserting CPT and static content at every X post, is this possible?
- loop through posts and display inserted media and post title as a link
- Custom Blog Loop on Home Page
- Exceprt not displaying
- Add File Attachment Name and URL into Javascript
- Updating Post meta (ACF field) from Feed
- How to separate post titles with a comma in the loop?
- get_posts changes main query
- Looping to organize and display custom posts by category using PHP and WordPress
- Trying to get property ‘post_content’ of non-object
- Exclude category and post from loop in custom category.php
- WordPress loop : how to exclude some posts with their status?
- what’s the syntax for if the image exists get the image?
- Homepage Loop Somehow Breaks Styling Of Post Grid
- how to remove replicating a tag inside loop?
- My query keeps looping infinitely ! how to stop it?
- Archive sorted by month – separate
- Can’t print out returned value
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Get query result before posts are displayed?
- WordPress Group By Problem
- the_post_thumbnail unless video id is added
- Home page loop with pagination problem
- Way of getting queried loop before the query with a filter hook?
- Loop not displaying comments_popup_link
- WooCommerce custom loop pagination on front page
- WordPress post pagination on custom template not working
- Problem with ms-thumb-frame-selected class in Master Slider
- I want the first post on my home page to be lengthier than the rest (example included)
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- How can you make it so the comment box shows on some pages or posts but not all?