Board logo

subject: Adding post thumbnails in wordpress [print this page]


Adding post thumbnails in wordpress
Adding post thumbnails in wordpress

In this article I will tell you how to add post thumbnails in your wordpress theme, and in the other part of the tutorial I will show you how to use them.

To add the support for posting custom thumbnails firstly you need to open your functions.php file. In here you have to add the following code:

add_theme_support( 'post-thumbnails' );

set_post_thumbnail_size( 80, 80, true );

The first line will enable post and pages thumbnail support for the theme. This is the most important line, as without it the thumbnails wouldn't work. The second line is optional, it tells the theme what size will the thumbnail be, in this case 80pixels (width) by 80pixels (height).

Now we finished telling wordpress that we want our thumbnails to be enabled, but we didn't tell it where we want them. So to do this we need to open the page where our posts or pages are situated. This may vary from theme to theme. Most oftenly it will be directly in the index.php file. Next step is finding "the loop":

More about the loop here

Now I will show you two options. One option is to simply add the thumbnail code inside the loop. And in result when wordpress will find that the author has added his thumbnail it will display it, and when the thumbnail isn't added, it won't do anything. So here is the code, wchich you must add between the loop:

Now for the second option, if you want to display a default image when the author didn't add any thumbnail of his own, you must apply this code:




welcome to loan (http://www.yloan.com/) Powered by Discuz! 5.5.0