WP posts on external page…*with thumbnails*
-
Hello, I am trying to get the latest WP posts onto a non-WP page within the site. I have been using this method (as recommended elswhere in this forum) https://www.jamischarles.com/blog/get-wp-posts-without-hacking/
However, this method only includes the Post Title and Permalink. I was able to modify the above script to also include an excerpt of the post below the title and link. However, I also want to include the post thumbnail so that I can display an image next to the link and excerpt. I have tried many many things but somehow I am unable to make this work. There doesn’t seem to be an obvious way to call the thumbnail like there is the title ($post_title).
The page in question is here: https://www.christmas-cookies.com/wptest.php
function displayHomePosts(){ //default values obj from post.php. //pass these in as args that you really want $defaults = array( 'numberposts' => 5, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'suppress_filters' => true ); $args = array( 'numberposts' => 4 ); //explore why the redirect error occurs? //$num = 5; $post_array = get_posts($args ); //as found in wp-includes/post.php //var_dump($post_array); //add the last className for the bottom border? echo "<ul>"; for($i=0; $i<count($post_array); $i++){ $post_title = $post_array[$i]->post_title; $shortpost_title = substr($post_title, 0, strpos($post_title, ' ', 10)); $post_name = $post_array[$i]->post_name; $post_content = $post_array[$i]->post_content; $post_blurb = substr($post_content, 0, strpos($post_content, ' ', 200)); $post_permalink = "https://www.christmas-cookies.com/blog/" . $post_name; //actually output the html with the php variables included echo "<li><b><a href=\"$post_permalink\" rel=\"bookmark\" title=\"Permanent Link to $post_title\">$post_title</a></b><br />$post_blurb... <a href=\"$post_permalink\">Read <b>$shortpost_title >></b></a></li>"; } echo "</ul>"; }
Can someone please tell me how to add the thumbnail? THANK YOU!
- The topic ‘WP posts on external page…*with thumbnails*’ is closed to new replies.