<?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>Themocracy WordPress Themes &#187; images</title>
	<atom:link href="http://themocracy.com/tag/images/feed/" rel="self" type="application/rss+xml" />
	<link>http://themocracy.com</link>
	<description>WordPress Theme Design</description>
	<lastBuildDate>Mon, 26 Jul 2010 06:18:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress 2.9 &#8211; Using Post Thumbnails</title>
		<link>http://themocracy.com/2010/02/wordpress-2-9-using-post-thumbnails/</link>
		<comments>http://themocracy.com/2010/02/wordpress-2-9-using-post-thumbnails/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 11:20:20 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[thumbnails]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=229</guid>
		<description><![CDATA[With WordPress 2.9 comes a revised image thumbnail system &#8211; previously, support for posts with attached thumbnails was a little haphazard (it is a fiddly business in terms of the programming), but this is a significant step forward.
The need is for a series of images, of given size, associated with a series of posts &#8211; [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fwordpress-2-9-using-post-thumbnails%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fwordpress-2-9-using-post-thumbnails%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2010/02/wordpress-admin-thumbnail-widget.png" alt="" title="wordpress-admin-thumbnail-widget" width="307" height="212" class="alignright size-full wp-image-231" /><strong>With WordPress 2.9 comes a revised image thumbnail system</strong> &#8211; previously, support for posts with attached thumbnails was a little haphazard (it is a fiddly business in terms of the programming), but this is a significant step forward.</p>
<p>The need is for a series of images, of given size, associated with a series of posts &#8211; maybe for a front page with post excerpts and their images, or for a featured posts slideshow. Before 2.9, every theme developer had a different way of doing it &#8211; some with patent recipes for determining (guessing) which thumbnail was attached to which posts, while other themes required the web admin to add a thumbnail custom meta field manually, a bit tiresome.<br />
<span id="more-229"></span></p>
<h3>add_theme_support()</h3>
<p>Firstly, you do have to explicitly declare the new thumbnail system in <strong>functions.php</strong> &#8211; and best to wrap it up in an &#8220;if function exists&#8221; to avoid problems for older WP installs.</p>
<pre class="brush: php">
// to prevent  WP &lt; 2.9 breaking
if (function_exists(&#039;add_theme_support&#039;)) {
add_theme_support( &#039;post-thumbnails&#039; );
}
</pre>
<p>This produces a whole new little widget on admin post edit pages. In terms of admin, you can now attach a thumbnail image to a post using this widget, (or by adding an image via the media gallery, as before), and then taking the &#8220;Use as thumbnail&#8221; option<br />
<img src="http://themocracy.com/wp-content/uploads/2010/02/wordpress-admin-add-thumbnail.png" alt="" title="wordpress-admin-add-thumbnail" width="477" height="110" class="aligncenter size-full wp-image-230" /></p>
<h3>Usage</h3>
<p>Now, you have the <strong>has_post_thumbnail()</strong> and <strong>the_post_thumbnail()</strong> template tags available &#8211; so in the post loop,  say for <strong>home.php</strong></p>
<pre class="brush: php">
&lt;?php if ( has_post_thumbnail()) { ?&gt;

	&lt;div class=&quot;thumbnail&quot;&gt;
		&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;
		&lt;?php the_post_thumbnail(); ?&gt;&lt;/a&gt;
	&lt;/div&gt;

 &lt;?php	} ?&gt;
</pre>
<p><strong> has_post_thumbnail()</strong> tests whether a thumbnail exists for the post &#8211; if so, go on to display it with <strong>the_post_thumbnail()</strong>. You could also add an else here and go to display a default image if there isn&#8217;t a thumbnail</p>
<p>So far so good &#8211; but what size are the thumbnails going to be?</p>
<h3>Sizing Thumbnails</h3>
<p>This is where the complications arrive &#8211; but the good news there&#8217;s now various ways to control the whole system, giving you a better chance of getting what you want, fairly painlessly&#8230; There&#8217;s 3 main ways of doing it.</p>
<p>First, you can specify the image dimensions directly as variables in the template tag</p>
<pre class="brush: php">
	the_post_thumbnail(array(150,90));
</pre>
<p>Note that the variable is an array. This method is fine enough if the theme is simply using one size of thumbnail &#8211; it does give some odd results if you start elaborating, with different sizes on different pages, so&#8230; </p>
<p>Secondly, back in <strong>functions.php</strong></p>
<pre class="brush: php">
if (function_exists(&#039;add_theme_support&#039;)) {
add_theme_support(&#039;post-thumbnails&#039;);
set_post_thumbnail_size(150, 90, true);
}
</pre>
<p>The set_post_thumbnail_size gives a default, here 150px width, 90px height &#8211; the 3rd variable is the &#8220;hard-crop&#8221; flag mode. 2 ways to go here, box-resizing (flag= false) and hard-cropping (flag=true).</p>
<p><strong>Box resizing </strong> = shrinks an image until it fits the width or height value you&#8217;ve specified. So with this method, you always get the whole image in the thumbnails, but the thumbnails themselves might turn out to be different sizes, width or height.</p>
<p><strong>Hard-cropping</strong> = the image is cropped to match the aspect ratio &#8211; width : height &#8211; and then shrunk to fit. So here you get all thumbnails the same size, but they may be missing cropped parts top/bottom or left/right. In practice, for general theme development, this is usually the best way to go.</p>
<p>Thirdly for sizing, you can use <strong>add_image_size()</strong></p>
<pre class="brush: php">
if (function_exists(&#039;add_theme_support&#039;)) {
	add_theme_support( &#039;post-thumbnails&#039; );
	set_post_thumbnail_size( 150, 90, true ); // default thumbnail size
	add_image_size(&#039;index-thumbnail&#039;, 120, 75); // for front page thumbnails
	add_image_size(&#039;single-post-thumbnail&#039;, 300, 180); // a different thumbnail size on single post pages
}
</pre>
<p>Now, you&#8217;ve done all the hard work and can be used very simply like this:</p>
<pre class="brush: php">
	&lt;?php the_post_thumbnail(&#039;index-thumbnail&#039;); ?&gt;
</pre>
<p>Here, you have the most control over what&#8217;s going on.</p>
<p>I suspect there may be one or two refinements in the pipeline, but these methods have made it much easier to handle thumbnails in themes &#8211; not least you won&#8217;t have to show users how to add custom fields manually. Good effort&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/wordpress-2-9-using-post-thumbnails/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
