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!

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


Plugin to display favorite posts as mini thumbnails on one page?

Here is the link where it is used: http://lovetaza.com/once-upon-a-time/

I'm 90% sure this has to be a plugin. Anyone seen this used else where and know how to make it happen on a Wordpress blog?


2 Answers

I doubt it's a plugin. If it's WordPress, it's probably using Featured Images aka the_post_thumbnail() http://codex.wordpress.org/Function_Reference/the_post_thumbnail

Okay, now that I have a few minutes, I can give a more detailed explanation of this

first, here's the definitive clearninghouse on info on this topic: http://codex.wordpress.org/Post_Thumbnails

Post Thumbnails (aka "featured images" in the backend) are images that you can assign and then call from The Loop. You have to set up sizes you want to use. In this case, they probably have a 150x150 (aka "thumbnail") size set and are calling a custom loop to show them one by one.

What you're probably more confused about might be how to make custom loops. This will be something incredibly important to your continued WP development, so I don't want to spoon feed it to you, but here's the basics:

Normally you're probably used to calling the loop this way:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     // here's some template tags
<?php endwhile; else: ?>
    // sorry no posts matched this loop
<?php endif; ?>


Now what's happening behind the scenes is that the loop query is being run by WordPress automatically depending on the URL. WP knows what sort of content you're requesting. Assuming the request is valid, WP unpacks that content with the_post() function. So while have_posts() is true, WordPress steps through the returned array of posts from the database, uses the_post() to unpack the content and allows you to use template tags to display the current item of the array. You are familiar with these content tags, things like the_title(). Most times when you see a the_ function, it's a template tag and can only be called from the loop.

You don't have to rely on WordPress to launch queries for you however, you can do them yourself using WP_Query(). WP_Query allows you to set up your own loops with complex logic. So I can say, pull all the posts that are tagged with a certain tag and then loop through them, displaying the thumbnails.

Read all the docs on WP_Query (http://codex.wordpress.org/Class_Reference/WP_Query) and if you're still confused, here's another great tutorial on it. http://wp.smashingmagazine.com/2013/01/14/using-wp_query-wordpress/

Think about a bit and maybe try to utilize tags or categories to create and easily query-able list for the posts you wish to pull thumbnails for. Post your code if you get stuck and I'll try to help.