<?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>cogumello &#187; Thumbnails</title>
	<atom:link href="http://www.cogumello.com/tag/thumbnails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cogumello.com</link>
	<description>Damião Martins</description>
	<lastBuildDate>Mon, 05 Oct 2009 15:58:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Inserindo thumbnails automaticamente na home do WordPress</title>
		<link>http://www.cogumello.com/dicas/inserindo-thumbnails-automaticamente-na-home-do-wordpress/</link>
		<comments>http://www.cogumello.com/dicas/inserindo-thumbnails-automaticamente-na-home-do-wordpress/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 02:20:33 +0000</pubDate>
		<dc:creator>cOgumello</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Thumbnails]]></category>

		<guid isPermaLink="false">http://www.cogumello.com/?p=113</guid>
		<description><![CDATA[Diversos temas para WordPress exibem em sua home um resumo do post, juntamente com uma thumbnail. Este procedimento normalmente é feito utilizando os Custom Fields, na hora de publicar o post. Ou seja, você faz o upload da imagem e &#8230; <a href="http://www.cogumello.com/dicas/inserindo-thumbnails-automaticamente-na-home-do-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cogumello.com/dicas/inserindo-thumbnails-automaticamente-na-home-do-wordpress/"><img src="http://www.cogumello.com/wp-content/uploads/2009/09/modelo_img_post.jpg" alt="Dicas de WordPress" title="Dicas de WordPress" width="629" height="163" class="alignnone size-full wp-image-126" /></a></p>
<p>Diversos temas para WordPress exibem em sua home um resumo do post, juntamente com uma thumbnail. Este procedimento normalmente é feito utilizando os <em>Custom Fields</em>, na hora de publicar o post. Ou seja, você faz o <em>upload</em> da imagem e em seguida copia a sua URL e a coloca no Custom Field correspondente. Mas, convenhamos, este processo não é nada usual e dependendo da situação, pode dar um pouco de trabalho na publicação.<br />
<span id="more-113"></span><br />
Procurando algum método mais prático, me deparei com <a href="http://www.hotpress.com.br/usando-os-thumbnails-gerados-pelo-wordpress-no-seu-tema/">este</a> do blog <a href="http://www.hotpress.com.br">HotPress</a>. Após algumas adaptações minhas, ele ficou assim:</p>
<pre class="brush: php; ">

&lt;?php
	// Busca a imagem anexadas ao post
	$args = array(
	&#039;post_type&#039; =&gt; &#039;attachment&#039;,
	&#039;post_mime_type&#039; =&gt; &#039;image&#039;,
	&#039;numberposts&#039; =&gt; -1,
	&#039;order&#039; =&gt; &#039;ASC&#039;,
	&#039;post_status&#039; =&gt; null,
	&#039;post_parent&#039; =&gt; $post-&gt;ID
	);

	// Verifica se exite alguma imagem anexada e pega sua URL
	$attachments = get_posts($args);
	if ($attachments) {
	foreach ($attachments as $attachment) {
	$img = wp_get_attachment_thumb_url( $attachment-&gt;ID );
	break;
	}

	// Busca Permalink e o Título do Post
	$link = $post-&gt;guid;
	$title = $post-&gt;post_title;

	// Agora que já temos a URL da imagem, o título e a Permalink do post, inserimos isso no HTML
	echo &quot;&lt;div class=&#039;img&#039;&gt;&lt;a href=&#039;$link&#039; title=&#039;$title&#039;&gt;&lt;img src=&#039;$img&#039; alt=&#039;$title&#039; /&gt;&lt;/a&gt;&lt;/div&gt;&quot;;
	}
	else echo &quot;&quot;;
?&gt;
</pre>
<h6>Explicação:</h6>
<p>Na primeira parte, buscamos as imagens anexadas ao post e, se existir, busca sua URL da sua <em>thumbnail</em> através do <em>wp_get_attachment_thumb_url</em>.<br />
Em seguida buscamos o Permalink do post e o Título, para ser usado no link e no atribulo alt da imagem, respectivamente.</p>
<h6>Implementação:</h6>
<p>Para funcionar, basta implementar o código acima dentro do <em>loop</em> no wordpress. Exemplo:</p>
<pre class="brush: php; ">

&lt;?php if (have_posts()) : ?&gt;
&lt;?php while (have_posts()) : the_post(); ?&gt;

// Insira o código aqui

&lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;
</pre>
<p></p>
<h6>Tamanho da Thumbnail:</h6>
<p>O tamanho da thumbnail vem configurado em <strong>150x150px </strong>como <em>default</em>, mas você pode alterá-lo no próprio painel do WordPress, em <strong>Configurações » Mídia</strong>.</p>
<p><img src="http://www.cogumello.com/wp-content/uploads/2009/09/config.jpg" alt="Configurações &gt; Mídia" title="Configurações &gt; Mídia" width="620" height="244" class="alignnone size-full wp-image-136" /></p>
<p>Bom, por enquanto é isso e qualquer problema é só dar um grito aí nos comentários. <img src='http://www.cogumello.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.cogumello.com/dicas/inserindo-thumbnails-automaticamente-na-home-do-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
