Get image from a wordpress post -
i have title of last 4 posts need image post too. i'm terrible programmer `
include('../blog/wp-load.php'); // blog path // last 4 posts $recent_posts = wp_get_recent_posts(array( 'numberposts' => 4, 'category' => 0, 'orderby' => 'post_date', 'post_type' => 'post', 'post_status' => 'publish' )); // display them list echo '<ul>'; foreach($recent_posts $post) { echo '<li><a href="', get_permalink($post['id']), '">', $post['post_title'], '</a></li>'; } echo '</ul>'`
i'm trying this:
i think you're looking get_the_post_thumbnail
here's codex.
for example:
get_the_post_thumbnail( $postid,'medium', array( 'class' => 'aligncenter' ));
you might try final product (untested):
// display them list $output = '<ul>'; foreach($recent_posts $post) { $link = get_permalink($post['id']); $image = get_the_post_thumbnail( $postid,'medium', array( 'class' => 'aligncenter' )); $title = $post['post_title']; $output .= '<li> <a href="'.$link.'">'. $image .'<h2>'.$title.'</h2> </a> </li>'; } $output .= '</ul>'; echo $output;
Comments
Post a Comment