Display Random Posts with thumbnail instead of just a title of the post

You can get the post thumbnail HTML using the function get_the_post_thumbnail(), so you just need to replace get_the_title() with that function: $string .= ‘<li><a href=”‘. get_permalink() .'”>’. get_the_post_thumbnail() .’ </a></li>’; By default the image will be the size defined by your theme, but you use any of the other available sizes by passing the size … Read more

Regarding to the performances, should I check if a post has a thumbnail before or after checking if is the front page (or single page, etc.)?

Neither, they are just as fast as each other, both are using information that has already been fetched in advance. This is micro-optimising. Functions such as is_front_page or is_singular etc etc are just looking up variables already set in the main query object. Likewise functions such as has_post_thumbnail etc are looking up data that has … Read more

Get Post Thumbnail Outside of Loop

Off top of my head here’s two possible solution concepts. 1) Just run the custom loop (I meant to type, query) again and this time use it with only the_post_thumbnail. <?php if ($myposts->have_posts() ) : ?> <div class=”image-wrapper e-in”> <?php while ($myposts ->have_posts() ) : $myposts ->the_post(); ?> <div class=”image “> <!–Post Iamge Will Show … Read more

php code for image fetching

How to fetch the featured image in wordpress post[?] echo get_the_post_thumbnail( $post_id ); Or, inside a proper Loop, the_post_thumbnail(); But I have a feeling that there is information missing from the question. You aren’t using any Core functions and there is no explanation why, or reasons why not. For example, WP_Query would be far easier … Read more