Jump to content

WordPress Featured Image Help


Nismo240
 Share

Recommended Posts

I'm trying to make a custom display of 2 of the most recent news/blog post in my WordPress but i'm having issue getting the URL for the featured image i gave to each of my post's.. My code is as follows (note that the printed text isn't formatted yet, just wanted a simple layout for testing purposes)

<?php$args = array( 'numberposts' => '2', 'order' => 'DESC','post_status' => 'publish' );$recent_posts = wp_get_recent_posts( $args );foreach( $recent_posts as $recent ){$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );echo 'Post ID: '.$recent["ID"];echo '<BR>';echo 'Post URL: '.get_permalink($recent["ID"]);echo '<BR>';echo 'Post Title: '.$recent["post_title"];echo '<BR>';echo $feat_image;              //Will display http://blablah.com/wordpress/blablahblah.jpg   etc....echo '<BR>';echo 'Post Content: '.$recent["post_content"];echo '<BR>';echo '<BR>';}?>

It all works except for the featured image :/ Thanks in advance :)

Link to comment
Share on other sites

if image is stored as location of the image you have to use <img> tag to display it.

Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...