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

Shaun Taylor
Shaun Taylor
2,654 Points

Adding thumbnails to Blog index page

I've been following the Bootstrap to Wordpress videos and I have created a fully functioning blog listings (index) page along with the single blog pages and also the archive pages etc...

However, on this page: http://new.synergypersonnelservices.co.uk/latest-news/ I would now like to add thumbnails to each of the blog posts.

SO when my client adds a featured image to a blog post, It can pull that featured image and show a thumbnail next to the blog post. Similar to this I guess: http://www.citygridmedia.com/developer/wp-content/uploads/2012/04/CityGrid-Wordpress-Listing-Template.png

I would like these thumbnails to stay square, but not to distort the original image (Perhaps it only shows the middle of the original image in its square container.

Any help would be greatly appreciated!!

Many thanks,

Shaun.

4 Answers

Colin Marshall
Colin Marshall
32,861 Points

You'll want to consult the Post Thumbnails section of the WordPress Codex.

You have to first enable support for post thumbnails in your theme's functions.php file. After that you can use the get_the_post_thumbnail() function in your loop.

Jacobus Hindson
Jacobus Hindson
14,429 Points

Hi Shaun,

As Colin said the Wordpress Codex is a good reference source, you mentioned you are following the BS to WP Course. When you get to Section 3 of that course there is a great follow along explanation for creating a Image Slider and also extracting Post Thumbnails. I would suggest working through the course to that point or if you want to skip ahead look here.

First of all you need to enable post thumbnail feature, if you haven't done that already you can do that by adding this to your functions.php file. add_theme_support( 'post-thumbnails' );

And then you can do something like this

if ( has_post_thumbnail() ) { the_post_thumbnail(); }

wrap this inside a div and add some styling to make it look better.

Here is something that I have done, for a similar layout for a website that I built.

<div class="featured-image col-md-3 pull-right"> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?> </a> <?php endif; ?> </div>

Please check WordPress codex to know more. http://codex.wordpress.org/Post_Thumbnails

Shaun Taylor
Shaun Taylor
2,654 Points

Hi guys, Thank you so much for these answers - I'll action soon and tick the best answer - I haven't been getting the notifications so I was unaware I had answers - Thanks again :)