<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP and Web Development Blog &#187; post thumbnails</title>
	<atom:link href="http://www.ebrueggeman.com/blog/tag/post-thumbnails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ebrueggeman.com/blog</link>
	<description>Tips and Tricks for Web Developers</description>
	<lastBuildDate>Thu, 19 Feb 2009 06:04:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Wordpress Posts with Thumbnails</title>
		<link>http://www.ebrueggeman.com/blog/creating-wordpress-posts-with-thumbnails/</link>
		<comments>http://www.ebrueggeman.com/blog/creating-wordpress-posts-with-thumbnails/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 14:21:17 +0000</pubDate>
		<dc:creator>Elliott Brueggeman</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[post thumbnails]]></category>

		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/?p=45</guid>
		<description><![CDATA[Creating blog posts is extremely easy in Wordpress, but adding simple thumbnails to your posts is not. I’m not talking about adding images within the post content, but adding them to your theme so they display in a standardized way in your blog loop, and on individual post pages.
The problem is that though Wordpress allows [...]]]></description>
			<content:encoded><![CDATA[<p>Creating blog posts is extremely easy in Wordpress, but adding simple thumbnails to your posts is not. I’m not talking about adding images within the post content, but adding them to your theme so they display in a standardized way in your blog loop, and on individual post pages.</p>
<p>The problem is that though Wordpress allows inserting images within posts, there is no way to “attach” these images to the post, so that theme designers can pull standardized images out for display. By making a few changes to your Wordpress configuration and your theme templates, and by using the Post Thumbnails plugin that I have written, you will be able to add thumbnails to your site in an intelligent way.</p>
<h3>Wordpress Configuration</h3>
<p>First step is to login to your Wordpress admin dashboard and navigate to the Settings -> Miscellaneous page. Here you will need to change:</p>
<p>- Uncheck the “Organize my uploads into month- and year-based folders.”</p>
<p>- Change the Wordpress thumbnail size to your desired size. This is important! Take careful thought when making this decision – you will break old post’s thumbnails if you chose to change this value later. I recommend 50&#215;50 pixels.</p>
<h3>Plugin Installation</h3>
<p>Download the Post Thumbnail plugin using this <a href="http://www.ebrueggeman.com/blog/wp-content/php_examples/post-thumbnail.zip">link</a>. Unzip it and place the file within your wp-content/plugins/ directory. Navigate to the Plugins menu within the Wordpress admin dashboard and activate this plugin.</p>
<p>You’re going to need a default post thumbnail to be used when no image is associated with a post. Upload an image that is the same size as the thumbnail size you chose above to the wp-admin/uploads folder, or the same folder you have chosen for uploads if you’re using a custom location. On most installations that folder would be wp-content/uploads/.</p>
<p>After you’ve uploaded the image, paste the name into the first line of code in the plugin PHP file:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'DEFAULT_POST_THUMBNAIL'</span><span style="color: #339933;">,</span> <span style="">'default_thumbnail_file.jpg'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Change the above default_thumbnail_file.jpg to whatever your image was called.</p>
<h3>Plugin Usage</h3>
<p>After the plugin has been activated, you will notice a new box titled Post Thumbnail on the Wordpress Write and Edit screens. To get a thumbnail attached to your post, upload an image using Wordpress’ default image uploading mechanism, which is a button next to the Add Media label near the top of those screens. This opens up a popup window for uploading images. Upload your image, but you don’t need to insert it into the post. Instead copy the file name (ex. myimage.jpg) and then click on the X to close the window.</p>
<p>Next, paste the file name into the Source Image input field in the Post Thumbnail box and click save. After saving, you will notice that an image name will be displayed in the Generated Thumbnail box. This is the thumbnail version of your source image, that Wordpress resized for you when you initially uploaded the image.</p>
<p><img class="alignnone size-medium wp-image-47" title="admin_preview" src="http://www.ebrueggeman.com/blog/wp-content/uploads/2008/11/admin_preview-300x171.png" alt="" width="300" height="171" /></p>
<h3>Adding the Thumbnail to Your Theme</h3>
<p>Now that thumbnails are being attached to posts, we need to modify our theme to display them. It’s up to you to decide where you want to place them, but I would recommend adding the thumbnail to your template wherever you use the Wordpress loop. Below is a code snippet that inserts a thumbnail into the Default Wordpress theme’s index.php file, so thumbnails will show up on the main page of your site. Only one new line needs to be added.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;div class=&quot;post&quot; id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    &lt;h2&gt;
    &lt;!-- Begin New Code--&gt;
    &lt;div style=&quot;float:left; margin:5px;&quot;&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> get_post_thumbnail<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/div&gt;
    &lt;!-- End New Code--&gt;
    &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to 
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h2&gt;
    &lt;small&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="">'F jS, Y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;!-- by <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> --&gt;
    &lt;/small&gt;
&nbsp;
    &lt;div class=&quot;entry&quot;&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="">'Read the rest of this entry &amp;raquo;'</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/div&gt;
&nbsp;
    &lt;p class=&quot;postmetadata&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span><span style="">'Tags: '</span><span style="color: #339933;">,</span> <span style="">', '</span><span style="color: #339933;">,</span> <span style="">'&lt;br /&gt;'</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span> 
    Posted in <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_category<span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> | 
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> edit_post_link<span style="color: #009900;">&#40;</span><span style="">'Edit'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="">' | '</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>  
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> comments_popup_link<span style="color: #009900;">&#40;</span><span style="">'No Comments &amp;#187;'</span><span style="color: #339933;">,</span> 
    <span style="">'1 Comment &amp;#187;'</span><span style="color: #339933;">,</span> <span style="">'% Comments &amp;#187;'</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/p&gt;
  &lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here’s what my above post looked like with the above template code:</p>
<p><img class="alignnone size-medium wp-image-46" title="post_preview" src="http://www.ebrueggeman.com/blog/wp-content/uploads/2008/11/post_preview-300x193.png" alt="" width="300" height="193" /></p>
<p>Other templates like single.php and archive.php in the Default theme have very similar code where you can also insert the thumbnail. Your theme may differ, but usage is very simple. Just call the following function in your template wherever you want to display the thumbnail:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> get_post_thumbnail<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ebrueggeman.com/blog/creating-wordpress-posts-with-thumbnails/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
