Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Marina Ferreira
Marina Ferreira
6,276 Points

Display post image on homepage

Hi! I'm trying to display an image (added via "add media" button) from a blog post (not custom post), on my homepage, but I cannot get the url right. Does anyone knows how to reference the file name. I tried : get_the_post_thumbnail( ); and got nothing, added an if statement with has_post_thumbnail( $post_id ); that returns false, tried get_attached_file($x); and nothing...... any thoughts?? Thanks so much!

2 Answers

Hey marina,

Hope this could be helpful http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

cheers

Matt Campbell
Matt Campbell
9,767 Points

You need to add theme support for thumbnails and then it's just the reference in the loop you need. the_post_thumbnail.

Codex has everything you need and it's literally two lines of code to get it working. :)