the_post_thumbnail()
can only be used in “the Loop”. What you need is get_the_post_thumbnail()
. (See details and code examples on the code reference page).
So something like:
foreach( $recent_posts as $recent ){
echo '<li>';
echo get_the_post_thumbnail( $recent['ID'], 'size', array( 'class' => 'alignleft' ) );
echo '<a href="' . get_permalink($recent["ID"]) . '">' . ( __($recent["post_title"])).'</a></li> ';
}
Where ‘size’ is whatever registered thumbnail size you want for the image.
Related Posts:
- The the_post_thumbnail without srcset?
- Get the first image from post content (eg.: hotlinked images)
- How to add a 2nd “featured image” to a post?
- How to change post thumbnail title and alt attributes to post title?
- Unexpected width and srcset attributes for the_post_thumbnail();
- How to handle thumbnails
- Change display of featured image for pages in twenty seventeen theme
- How to set dimensions of the post thumbnails (featured images)
- How to regenerate thumbnails when they’re stored on S3
- Cannot get full thumbnail size using the_post_thumbnail
- Can’t show custom post thumbnail sizes as background images
- Featured Images are not able to be set
- Reasons why all thumbnail sizes aren’t working
- How do I Add images uploaded in the post to a default custom field
- How do I build a post_thumbnail based archive? [closed]
- How do I turn a post thumbnail into a background image?
- Reactor Theme: Prevent Post Thumb on Post
- Featured Image meta box not showing up
- How do I remove inline style in featured image markup?
- Set a featured image as a replacement to the header image
- Dynamic Post Thumbnail →
- Issue on Getting Custom post type Thumbnail’s URL
- How To Pick Custom Size Of Uploaded Image In Theme Via the_post_thumbnail();?
- How to disable thumbnail filter for a specific template part or image size?
- the_post_thumbnail() get the URL to the “medium” sized image
- Full width featured thumbnail
- How can I get the featured image or the first image for a post/page and display it as a banner?
- How to make excerpt image be full size instead of thumbnail?
- How can I scale down the width of images in bulk that are embedded in posts throughout the site?
- Add image URL automatically to custom field?
- theme directory fallback image outputs url and not the image
- Created blank theme for REST API, featured image not appearing on admin side
- Full width thumbnail
- Featured Image Module Randomly Disappears
- Single Featured Image Repeating
- Any disadvandages if I style the wordpress align classes without img and .wp-caption prefix
- apply_filters to featured image
- Show post thumbnail only if it exists using timthumb
- Display Page featured Image as well as Posts featured Image
- How do I work with responsive images in WordPress? (img srcset/sizes)
- I want to resize post featured image without cropping image. How?
- Getting failure when using filemtime() with wp_enqueue_style
- Is it possible ( or advisable) to allow open access to the new theme customizer for potential clients?
- How bad is it if I write AJAX functions using wp-load.php?
- How to know if a child theme is being used?
- wp_nav_menu sort order?
- Snippet: Use classes instead of inline styles for text alignment
- Make a custom theme translate-ready
- Grab the first paragraph of each post
- Wrapper class: How to get rid of call_user_func_array() warning?
- Change Genesis Tag from Page Template [closed]
- How to Handle CSS for Multiple Header header.php Files?
- Adding WordPress colorpicker in widget settings
- What is wrong with this code I have to make a blockquote shortcode
- How to attach different React Components to different Dom Roots using the new WP wordpress/scripts webpack/babel
- Remove Cookies From WordPress Core
- Is it necessary to prefix every css class in a theme framework?
- Warning/Error in Admin Panel while developing theme
- Where can I access my custom page template?
- How to display posts in hyperlink with nested slugs?
- Check if tag, category or author on archive.php
- Editing Footer Information
- Developing WordPress Theme using CSS framework like Bootstrap
- Apply different Class for each element in a foreach()
- Fatal error in comments.php
- the_permalink() doesn’t work
- Getting custom posts by post id from cutomizer text input
- How do i define the location of a git push to WP Engine
- WP_Comment_Query – Get comments and answers separately
- How to use widget in a widget-less WordPress theme?
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- In creating a theme, how can i allow a user to change an image outside post/page content?
- What Does “Cannot modify header information?” Mean
- What template file is used for homepage pagination?
- WordPress theme resource won’t load over VPN
- Templates without a loop, best practice?
- How the redirect_to parameter is added to wp_login.php when trying to access wp-admin?
- Converting a static HTML template into a WP theme – How do I specify page content?
- Unwanted empty line at the beginning of document
- Why is my container argument not working for wp_nav_menu() [closed]
- Translate a theme with a PO file
- All pages are the same
- How to Split loop in multiple column in archive page
- Auto focus RichText field
- Warning: This page allows direct access to your site settings. You can break things here. Please be cautious!
- How to get next post and previous post URL in loop, single.php My WordPress 4.9.6
- Import settings from another theme
- Load multiple css simultaneously using functions.php
- bbPress: modifying template for forum index
- control posts order by select option
- Nav menus Fast previewing not working with wp_get_nav_menu_items!
- Load get_page_templates into select menu
- how to make a new page affected by a theme’s index.php layout?
- problem with blank page
- Theme Options Doesn’t Work On WP Multisite
- WordPress two sidebar layout or theme
- add_action not working in header?
- Recent posts with comment count in “Sidebar” template [closed]
- HTML to WORDPRESS [closed]
- Theme’s featured image option is not showing up