Maybe this could be useful.
I used it on my own site to display a list of thumbnails.
<?php
// check if there's a thumbnail
if ( has_post_thumbnail($post->ID)) {
//show thumbnail
echo 'get_the_post_thumbnail($post->ID, 'thumbnail' , array('class' => "img-responsive yourClass"));
} else {
//show another image if there's not a thumb
echo '<img class="img-responsive" src="'.get_template_directory_uri().'/MISSING-PHOTOS.jpg">';
}
?>
Hope can help you.
Related Posts:
- How to create posts (not post template) to be displayed on projects page?
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Loop on front-page.php
- is there a way to retrieve posts that do not have a featured image assigned?
- WP_Query with custom post type ID
- display posts of custom post type with custom taxonomy
- Display post from custom post type
- How to fetch posts that are stored in the different table than (default) wp_posts?
- SEARCH QUERIES – REVERSE OUTPUT
- subtracting the current post form then whole loop, which is generating all CPT titles
- Custom post Query and WordPress Post Query Clash
- Only show current category post
- wp_query to find posts by year and month
- WP_Query is printing out only one post when posts_per_page is set to multiple
- How to get all posts except for one post from a certain custom post type?
- Remove duplicated values from a loop
- WordPress Orderby Numeric Value Not Working
- Custom Post Type Loop within Shortcode
- WP_Query | ‘post_type’ doesn’t work
- How to connect two custom post types with nested loops
- Filter by custom taxonomy slug on a custom post type
- Using global $post; to get featured image for custom post via WP_Query
- Query custom post type in the loop
- Loop through Custom Post Type, and then show children within each iteration
- Very Slow Page – How to Optimize # of Queries?
- Can I create a loop with multiple post types and specify different $args for each post type?
- How to add post_type=value when editing that post type in the WordPress admin?
- Display CPT posts based on specific taxonomy
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- WP_Query orderby modified to include custom meta changes
- How to make sure content doesn’t display if selection is empty
- Show one item per category of a custom post type
- Storing posts from query and accessing later via AJAX call
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Show custom post type filtered by category
- Custom loop with multiple taxonomy queries
- I would like to have different styles for my posts based on the content of each post
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Get latest 3 posts from multiple CPT in one query
- List custom taxonomy specific to one custom post type
- What’s the WP way to load remaining custom posts?
- Several post types on WP Query by tag and taxonomy
- WP Query with categories only shows one post and ignores the category
- Shortcode not working with post counter
- Problem: wp_query outputs all images on site
- Prioritize posts in query by meta keys?
- How to get all tags of a custom post type by id
- pagination not working for category.php (custom post types in categories)
- Redirect to another page using contact form 7? [closed]
- WP the_posts() on single-cars.php get category link
- Conditional for a Single Post That Belongs to a Category?
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- Different Limit number of post on different archive page
- How can I group posts by months and years?
- Multiple Custom Post Type queries, how to DRY it up
- Custon Content within WordPress Loop
- Loop increase number
- Using wp_query to modify the loop in index.php for a CPT
- Custom post types and ‘new WP_Query’
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- Variable not working in WP_Query
- 3 random images from custom post type, each in a div with a diffrent class
- get_pagination not working on a custom post type query (using WP_Query)
- How to Make infinite loop of post
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Pagination not working on custom query on a page
- Query within a foreach within a query (queryception)
- wordpress lists similar type of posts in a custom post type
- Auto post creation
- Dynamic pages for linked categories and content
- Get post format
- Custom wordpress loop
- Trying to add a class to post links
- How to Query in WordPress which shows Alphabetic Posts?
- displaying content of custom post type
- postsperpage value not being applied
- Posts are not rendering perfectly [closed]
- Display the current post in browser as the first post in a loop (for a slideshow)
- How to query Posts from a custom post type which contains a custom taxonomy?
- Use post in multiple places on a page with multiple posts
- List all Custom Post Type posts excluding certain Taxnomy term
- foreach loop inside the loop creating duplicates in output
- list posts of two post types in a single template
- The loop does not show users
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- How do I list a custom field and custom taxonomies for each result in a loop?
- If/Else child list for Custom Post Type single template within loop?
- Custom Post Type Query W/Category Dropdown
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Custom post type pagination error
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- What is the most efficient way to execute recursive complex queries?
- Page that lists publications by classifying them by taxonomy
- posts_per_page in custom WP_Query does not override “Reading” settings?
- i need to have a tab with gategory post