0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Custom Post Thumbnails in Two Steps

Alright, kids. Time for the ‘ol three-step custom-field tutorial. This time we’re going to implement post thumbnails. You know, representative images for each of your posts that may be displayed anywhere you wish, including outside of the flow of post content, and even outside of the loop. This is a great trick for advanced page layouts. Ready? Sharpen your keystrokes!

Step 1:
Open your write panel and create a key called “thumbnail”. Then, for the value of the “thumbnail” key, enter the URL of the thumbnail image for that particular post. Write the post and then publish it as normal. Wash, rinse, repeat to get a nice collection of posts with thumbnails. Or, go back to exisiting posts and add a thumbnail as we have just described.

Step 2:
Open your theme template file containing the loop and add the following code to the location where you would like the post thumbnail images to appear:

<?php $thumbnail = get_post_meta($post->ID, 'image', true); if ($thumbnail) { ?>

<img src="<?php echo $thumbnail; ?>" alt="" width="100" height="100" />

<?php } ?>

That’s it! Don’t forget to edit the width and height attributes of the <img> element to account for the proper image size.

Source: Perishable Press




0