Well, Wordpress 2.9 is finally here!!! And with it many new features, one of which is the new thumbnail feature. First let me show you few examples of how it looks like and how you can use it (for those who just want to copy the code scroll to the bottom of the post).
What is the Wordpress 2.9 thumbnail feature?
Once you upgrade to /or/ activate Wordpress 2.9 and get your thumbnail feature going (what will be shown in a minute), you will be able to create galleries inside your WP blog. This will enable you to show only the thumbnail on your home page and have the gallery of as many photos as you wish “behind” it. Here is how this will look like in the default setup:
Portfolio sites with Wordpress 2.9
What is great about this feature is that now (with a little knowledge of php and css), Wordpress can easily be used for creating portfolio sites which was much more complicated in the older versions. Here is an example of how I used it to create my graphic design portfolio site (this is still work in progress so pay attention only to the home page).
Explaining the code
Here is what you have to do to activate the new thumbnail feature in Wordpress 2.9. All code that follows should be placed inside your childthemes functions.php and styled in your childthemes style.css (read more about getting started with Thematic and childtheme). .
What we need to do is “call” the thumbnails (wordpress calls it the_post_thumbnail) inside the post content. Now, if we want the thumbnail feature to appear on each post we have to call for them inside the loop (loop is the list of things that each post goes through before being published). If you have no idea what am I talking about read more about the loop. Here goes…
<?php //* First we will add the thumbnail feature *// add_theme_support('post-thumbnails'); //* To create our own loop we have to get rid of thematic index loop first.*// function remove_index_loop() { remove_action('thematic_indexloop', 'thematic_index_loop'); } add_action('init', 'remove_index_loop'); // Now we will create our own loop. function thumb_index_loop(){ while ( have_posts() ) : the_post() // Start the loop: // This is just what we decide to show in each post ?> <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>"> <?php thematic_postheader(); ?> <div class="entry-content"> <?php the_post_thumbnail(); // we just called for the thumbnail ?> </div> <?php thematic_postfooter(); ?> </div><!-- .post --> <?php endwhile; // loop done, go back up } // And in the end activate the new loop. add_action('thematic_indexloop', 'thumb_index_loop'); ?> |
Note that our posts will include post header, post image (the thumbnail) and post footer. So we just added thumbnails to the blog. Also note that we wrapped the thumnails, header and footer inside divs so you can teyle them in your style.css.
And the code is there. Now all you need to do is use them. Go to your wordpress admin page and on the right side under the categories widget you will see the new one: POST THUMBNAILS. It will offer you to upload an image that will be used as the thumbnail for that post (just don’t forget to press “save all changes” after you upload an image). Also every time you upload an image to your gallery, you will have an option “use as thumbnail” next to the “insert into the post” button. In the same window you can choose do you want to use it as a link to the post or to the image itself or you don’t want it to be a link at all. After saving all changes the image should appear in your “post thumbnails” widget.

Now you can add as many images you want into the post but only the thumbnail will be visible on your home page.
And you are all set!


