<?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>Webdevtuts &#187; Thumbnail</title>
	<atom:link href="http://www.webdevtuts.net/tag/thumbnail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevtuts.net</link>
	<description>Making tutorials fun and easy!</description>
	<lastBuildDate>Mon, 23 Jan 2012 11:36:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Add Thumbnail to Post Using 2 Different Methods</title>
		<link>http://www.webdevtuts.net/wordpress/add-thumbnail-to-post-using-2-different-methods/</link>
		<comments>http://www.webdevtuts.net/wordpress/add-thumbnail-to-post-using-2-different-methods/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 18:06:02 +0000</pubDate>
		<dc:creator>Marcell Purham</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Thumbnail]]></category>

		<guid isPermaLink="false">http://www.webdevtuts.net/?p=277</guid>
		<description><![CDATA[Ever wanted to learn how to add a thumbnail to your Wordpress post? In this tutorial I will go over the basic fundamentals of adding a Wordpress thumbnail to your post. We will use two examples in this tutorial.   <a href="http://www.webdevtuts.net/wordpress/add-thumbnail-to-post-using-2-different-methods/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to learn how to add a thumbnail to your WordPress post? In this tutorial I will go over the basic fundamentals of adding a WordPress thumbnail to your post. We will use two examples in this tutorial.  </p>
<h1>Adding the thumbnail code</h1>
<p>Adding a Thumbnail to your WordPress is very simple and easy. To add a WordPress thumbnail to your post you would simpley add the code below to your index.php file. </p>
<pre><code>&lt;img src=&quot;&lt;?php echo get_post_meta($post-&gt;ID, &#039;Thumbnail&#039;,true) ?&gt;&quot; alt=&quot;Post Image&quot; id=&quot;post thumb&quot; /&gt;<!--formatted--></code></pre>
<p><img class="aligncenter" src="https://s3.amazonaws.com/webdevtuts/uploads/2009/08/code-place.jpg" alt="add to index.php"></p>
<p>The code above tells WordPress to get the thumbnail through a custom field. So to retrieve our image we would simply add the word &#8220;Thumbnail to our custom fields &#8221;<br />
<img class="aligncenter" src="https://s3.amazonaws.com/webdevtuts/uploads/2009/08/customfeilds.jpg" alt="add thumbnail"></p>
<pre><code>&lt;?php echo get_post_meta($post-&gt;ID, &#039;Thumbnail&#039;,true) ?&gt;<!--formatted--></code></pre>
<p>Styling the thumbnail is very simple. Depending on where you would like your image you would float the thumbnail to the left to align it on the left side or float it to the right to align it on the right side.<br />
<img class="aligncenter" src="https://s3.amazonaws.com/webdevtuts/uploads/2009/08/post_pre.jpg" alt="add to index.php"></p>
<pre>
<code>
#post_thumb 							{ float:left; padding:10px; width:225px; height:197px; }

#post_right 							{ float:left; padding:10px; width:225px; height:197px; }
</code>
</pre>
<p>Changing the width and height of the thumbnail is quite easy also. To change the height and width you would simply go to the css and edit the height and width.</p>
<pre>
<code>
height:197px;
Width:225px;
</code>
</pre>
<p>Intermediate:</p>
<p>I know as a developer when I design themes for clients I try to limit the amount of code in my files to make it easier for the client to edit or get something.<br />
In this method we will use our function.php file. Open your function.php and place this code inside</p>
<pre>
<code>
function retrieve_my_thumbnail() {
  global $post, $posts;
  $first_img = &#039;&#039;;
  ob_start();
  ob_end_clean();
  $output = preg_match_all(&#039;/&lt;img.+src=[\&#039;&quot;]([^\&#039;&quot;]+)[\&#039;&quot;].*&gt;/i&#039;, $post-&gt;post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = &quot;/images/default.jpg&quot;;
  }
  return $first_img;
}
<!--formatted--></code>
</pre>
<p>What the code above does is call your thumbnail through your functions.php file then it searches for the one line code in one of your WordPress templates. Usually the index.php file. </p>
<p><img class="aligncenter" src="https://s3.amazonaws.com/wbdevtuts/uploads/2009/08/function.jpg" alt="add to index.php"></p>
<p>Retrieve the image using the code below. The code below automatically retrieves an image from your post and turns it into a thumbnail ( Should be placed in your index.php template file)</p>
<pre>
<code><br />
&lt;img src=&quot;&lt;?php echo retrieve_my_thumbnail() ?&gt;&quot; alt=&quot;thumbnail&quot;/&gt;<br />
<!--formatted--></code></p>
<pre>
<p>That's it! Please share with your friends.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevtuts.net/wordpress/add-thumbnail-to-post-using-2-different-methods/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Content Delivery Network via Amazon Web Services: S3: webdevtuts.s3.amazonaws.com

Served from: www.webdevtuts.net @ 2012-02-07 17:54:28 -->
