<?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>Stereo Interactive &#38; Design - Ann Arbor, Michigan Web Design &#187; wordpress</title>
	<atom:link href="http://stereointeractive.com/blog/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereointeractive.com/blog</link>
	<description>Development Blog</description>
	<lastBuildDate>Fri, 04 Nov 2011 03:46:28 +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>WordPress 3.1 sortable admin tables</title>
		<link>http://stereointeractive.com/blog/2011/02/26/wordpress-3-1-sortable-admin-tables/</link>
		<comments>http://stereointeractive.com/blog/2011/02/26/wordpress-3-1-sortable-admin-tables/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 01:03:30 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=594</guid>
		<description><![CDATA[With the release of 3.1, WordPress enabled list-type admin screen enhancements to provide sortable columns for list-type screens and better pagination. This begs the question, how do we make our custom columns sortable, too? If we add custom meta attributes to posts or create custom post types, sometimes it&#8217;s nice to display these fields in [...]]]></description>
			<content:encoded><![CDATA[<p>With the release of <a href="http://codex.wordpress.org/Version_3.1">3.1</a>, WordPress enabled list-type admin screen enhancements to provide sortable columns for list-type screens and better pagination. </p>
<p>This begs the question, how do we make our custom columns sortable, too? If we add custom meta attributes to posts or create custom post types, sometimes it&#8217;s nice to display these fields in the admin tables. There are <a href="http://www.google.com/search?q=wordpress+custom+table+column">plenty of posts out there</a> that describe how do that. So, let&#8217;s focus on how to make these columns sortable.<span id="more-594"></span></p>
<p>A new filter was introduced called <code>manage_{$screen->id}_sortable_columns</code>. This works just like the existing filter that we use to add our own column headings to the table. Let&#8217;s imagine we created a meta field for our posts called &#8216;my_author&#8217;. (Remember, it&#8217;s a good idea to prepend your meta columns with a custom prefix. As an example we&#8217;ll use &#8220;my_&#8221; but you should probably use something more specific in your code. We usually use &#8220;stereo_&#8221;.</p>
<pre><code lang="php">
      // add this code to wherever you define your custom post type, usually within a plugin or your theme's functions.php file.
      // you should be familiar with this filter from earlier versions of wp...
      add_filter("manage_edit-".$post_type."_columns", 'my_edit_columns'));
      // this is the new filter which expects an array in the format of id => data
      add_filter("manage_edit-".$post_type."_sortable_columns", 'my_sortable_columns');

      // ...
        function my_sortable_columns($columns)
  	{
  	  $custom = array(
            // meta column id => sortby value used in query
  	    'my_author'    => 'my_author',
  	  );

  	  return wp_parse_args($custom, $columns);
  	}</code></pre>
<p>If you have it set up correctly, when you view your list of posts in the admin area, the columns defined in your my_sortable_columns function should be active links, and clicking on them toggle sort order.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2011/02/26/wordpress-3-1-sortable-admin-tables/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WordPress: Adding custom boxes to posts</title>
		<link>http://stereointeractive.com/blog/2011/02/26/wordpress-adding-custom-boxes-to-posts/</link>
		<comments>http://stereointeractive.com/blog/2011/02/26/wordpress-adding-custom-boxes-to-posts/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 22:43:15 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=592</guid>
		<description><![CDATA[I stumbled on a great post about how to custom boxes for your wordpress posts. In this case it was promo boxes, but it could be used anytime you want to relate certain custom types of content to your wordpress pages (for example, a portfolio of work, a list of employees, etc). http://wordpress.stackexchange.com/questions/5750/custom-field-meta-populated-by-dropdown-of-existing-posts]]></description>
			<content:encoded><![CDATA[<p>I stumbled on a great post about how to custom boxes for your wordpress posts. In this case it was promo boxes, but it could be used anytime you want to relate certain custom types of content to your wordpress pages (for example, a portfolio of work, a list of employees, etc).</p>
<p><a href="http://wordpress.stackexchange.com/questions/5750/custom-field-meta-populated-by-dropdown-of-existing-posts">http://wordpress.stackexchange.com/questions/5750/custom-field-meta-populated-by-dropdown-of-existing-posts</a></p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2011/02/26/wordpress-adding-custom-boxes-to-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving wordpress site to another server</title>
		<link>http://stereointeractive.com/blog/2010/04/19/moving-wordpress-site-to-another-server/</link>
		<comments>http://stereointeractive.com/blog/2010/04/19/moving-wordpress-site-to-another-server/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 02:35:34 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=511</guid>
		<description><![CDATA[There was a question posted on WP Questions about moving a wordpress from a local development server to the live server. Here is what I do for just about all of my WP sites. It works for me since while I&#8217;m building out a site I usually make local changes that I have to sync [...]]]></description>
			<content:encoded><![CDATA[<p>There was <a href="http://www.wpquestions.com/question/show/id/328">a question posted on WP Questions</a> about moving a wordpress from a local development server to the live server. Here is what I do for just about all of my WP sites. It works for me since while I&#8217;m building out a site I usually make local changes that I have to sync up to a staging site for people to review.</p>
<p>1. Edit your wp-config.php so it works on various environments. I do this like so:<br />
<span id="more-511"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="co1">// ** MySQL settings - You can get this info from your web host ** //</span>
<span class="kw1">switch</span> <span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">'SERVER_NAME'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="kw1">case</span> <span class="st_h">'mysite.local'</span><span class="sy0">:</span> <span class="co1">// local dev environment</span>
    <span class="co1">// ** MySQL settings - You can get this info from your web host ** //</span>
    <span class="co4">/** The name of the database for WordPress */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_NAME'</span><span class="sy0">,</span> <span class="st_h">'mylocal_db'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co4">/** MySQL database username */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_USER'</span><span class="sy0">,</span> <span class="st_h">'root'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co4">/** MySQL database password */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_PASSWORD'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co4">/** MySQL hostname */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_HOST'</span><span class="sy0">,</span> <span class="st_h">'localhost'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">break</span><span class="sy0">;</span>
  <span class="kw1">default</span><span class="sy0">:</span>
    <span class="co4">/** The name of the database for WordPress */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_NAME'</span><span class="sy0">,</span> <span class="st_h">'yourlive_db'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co4">/** MySQL database username */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_USER'</span><span class="sy0">,</span> <span class="st_h">'yourlive_dbuser'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co4">/** MySQL database password */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_PASSWORD'</span><span class="sy0">,</span> <span class="st_h">'yourlive_pw'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co4">/** MySQL hostname */</span>
    <span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'DB_HOST'</span><span class="sy0">,</span> <span class="st_h">'localhost'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">break</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>That will let you use the same wp-config.php file on either server.</p>
<p>2. I dump my local database. I do this using a little shell script that will search the mysql dump for my local url and replace it with the live one. I put the following in a file called dbdump.sh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span class="co0">#!/bin/bash</span>
&nbsp;
<span class="co0"># dump database</span>
mysqldump <span class="re5">-u</span> root mylocal_db <span class="sy0">&gt;</span> mylocal_db_dump.sql
&nbsp;
<span class="co0"># search inside the mylocal_db_dump.sql file for 'mysite.local' and replace with 'thelivesite.com'</span>
<span class="kw2">perl</span> <span class="re5">-pi</span> <span class="re5">-e</span> <span class="st_h">'s/mysite.local/thelivesite.com/g'</span> mylocal_db_dump.sql</pre></div></div>

<p>Then I can run this script with the command &#8220;./dbdump.sh&#8221; anytime I want to export my local database to an sql file to import on the live site.</p>
<p>3. I use rsync to sync my local version of the site up to the server. Alternatively, you could use FTP to upload the entire local site, but it&#8217;s harder to keep things in sync this way. If you want to use SSH, I put the following into a file named something like &#8220;upload.sh&#8221; and put it in my blog folder.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span class="co0">#!/bin/bash</span>
<span class="re2">GO</span>=<span class="re4">$1</span>
: <span class="co1">${GO:=&quot;&quot;}</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es2">$GO</span>&quot;</span> = <span class="st0">&quot;go&quot;</span> <span class="br0">&#93;</span>
<span class="kw1">then</span>
  <span class="re2">ARGS</span>=<span class="st0">&quot;-avc&quot;</span>
<span class="kw1">else</span>
  <span class="re2">ARGS</span>=<span class="st0">&quot;-avcn&quot;</span>
<span class="kw1">fi</span>
&nbsp;
rsync <span class="re1">$ARGS</span> <span class="re5">--stats</span> <span class="re5">--progress</span> <span class="re5">--exclude-from</span>=rsync_exclude.txt <span class="re5">-e</span> <span class="st_h">'ssh'</span> . username<span class="sy0">@</span>yourserver.com:<span class="sy0">/</span>home<span class="sy0">/</span>path<span class="sy0">/</span>to<span class="sy0">/</span>your<span class="sy0">/</span>public_html</pre></div></div>

<p>Basically what this does is execute the &#8220;rsync&#8221; command with a few arguments. It will look at the files in the current directory on your machine and compare them with the files on the server. If you execute this script with a &#8220;go&#8221; parameter, it will actually perform the copy; otherwise it does a dry-run to show you what changes would occur. I put a list of a few files to ignore while syncing in &#8220;rsync_exclude.txt&#8221;. I ignore any hidden files like .DS_Store, my custom upload shell script which we just created, and temporary files and uploads. </p>
<p>Here is what mine usually contains:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">.DS_Store
.htaccess
upload.sh
dbdump.sh
rsync_exclude.txt
<span class="sy0">/</span>wp-content<span class="sy0">/</span>cache<span class="sy0">/*</span>
<span class="sy0">/</span>wp-content<span class="sy0">/</span>uploads<span class="sy0">/*</span></pre></div></div>

<p>You can then run the upload.sh script by executing the command like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">.<span class="sy0">/</span>upload.sh</pre></div></div>

<p>And if it looks ok, you actually perform the sync with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">.<span class="sy0">/</span>upload.sh go</pre></div></div>

<p>4. Now we have all our files synced up&#8230; we just need to update the database. You can either either use something like phpMyAdmin to upload your &#8220;mylocal_db_dump.sql&#8221; file, or if you have SSH access you can execute it using your live mysql user:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">mysql <span class="re5">-u</span> yourlive_dbuser <span class="re5">-p</span> mylocal_db_dump.sql <span class="sy0">&gt;</span> yourlive_db</pre></div></div>

<p>This may seem like a lot of steps, but if you are rapidly developing your site and need to re-upload to a staging server frequently, this ends up saving a ton of time. Once you have the files in place, updating the live site is a simple matter of running these commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">.<span class="sy0">/</span>dbdump.sh
.<span class="sy0">/</span>upload.sh</pre></div></div>

<p>and then insert your SQL file into your live database, either through the command line or phpMyAdmin. </p>
<p>Now that I have these files I just copy them into any wordpress site I&#8217;m working on and I&#8217;m ready to upload as often as I want and it only takes a few seconds. I hope you find some use out of them, too.</p>
<p>If you want to download a bundle of the sample files I mention above, you can <a href='http://stereointeractive.com/blog/wp-content/uploads/2010/04/wordpressDeploy.zip'>download a zip archive of them here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/04/19/moving-wordpress-site-to-another-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress navigation, link to page or category</title>
		<link>http://stereointeractive.com/blog/2010/04/10/wordpress-navigation-link-to-page-or-category/</link>
		<comments>http://stereointeractive.com/blog/2010/04/10/wordpress-navigation-link-to-page-or-category/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 16:09:00 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=507</guid>
		<description><![CDATA[Here is a quick snippet of a non-elegant way to create a navigation for a wordpress template. This sample includes links to specific pages using get_permalink() and is_page(), along with get_category_link() and in_category(). Using these functions you can determine if each link should be in its active state or not. $links = array&#40; 'Industry Studies' [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick snippet of a non-elegant way to create a navigation for a wordpress template. This sample includes links to specific pages using <code>get_permalink()</code> and <code>is_page()</code>, along with <code>get_category_link()</code> and <code>in_category()</code>. Using these functions you can determine if each link should be in its active state or not.<br />
<span id="more-507"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="re0">$links</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span>
  <span class="st_h">'Industry Studies'</span> <span class="sy0">=&gt;</span> <span class="kw3">array</span><span class="br0">&#40;</span>get_permalink<span class="br0">&#40;</span><span class="nu0">12</span><span class="br0">&#41;</span><span class="sy0">,</span> is_page<span class="br0">&#40;</span><span class="nu0">12</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
  <span class="st_h">'Recipes'</span> <span class="sy0">=&gt;</span> <span class="kw3">array</span><span class="br0">&#40;</span>get_category_link<span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="br0">&#40;</span><span class="re0">$categoryId</span> ? <span class="nu0">3</span> <span class="sy0">==</span> <span class="re0">$categoryId</span> <span class="sy0">:</span> in_category<span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
  <span class="st_h">'Blog'</span> <span class="sy0">=&gt;</span> <span class="kw3">array</span><span class="br0">&#40;</span>get_category_link<span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="br0">&#40;</span><span class="re0">$categoryId</span> ? <span class="nu0">1</span> <span class="sy0">==</span> <span class="re0">$categoryId</span> <span class="sy0">:</span> <span class="br0">&#40;</span>in_category<span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> <span class="sy0">!</span>is_page<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
<span class="br0">&#41;</span><span class="sy0">;</span> 
&nbsp;
<span class="re0">$selected</span> <span class="sy0">=</span> <span class="kw4">false</span><span class="sy0">;</span>
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$links</span> <span class="kw1">as</span> <span class="re0">$title</span> <span class="sy0">=&gt;</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">:</span>
  <span class="re0">$linkSelected</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$selected</span> <span class="sy0">&amp;&amp;</span> <span class="re0">$link</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> ? <span class="br0">&#40;</span><span class="re0">$selected</span> <span class="sy0">=</span> <span class="kw4">true</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw4">false</span><span class="sy0">;</span>
  <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st_h">'&lt;li&gt;&lt;a href=&quot;%s&quot; class=&quot;%s&quot; title=&quot;%s&quot;&gt;%s&lt;/a&gt;&lt;/li&gt;'</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">,</span> <span class="br0">&#40;</span><span class="re0">$linkSelected</span> ? <span class="st_h">'selected'</span> <span class="sy0">:</span> <span class="st_h">''</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="re0">$title</span><span class="sy0">,</span> <span class="re0">$title</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">endforeach</span><span class="sy0">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/04/10/wordpress-navigation-link-to-page-or-category/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress get post images and the_post_thumbnail caption</title>
		<link>http://stereointeractive.com/blog/2010/02/12/wordpress-get-post-images-and-the_post_thumbnail-caption/</link>
		<comments>http://stereointeractive.com/blog/2010/02/12/wordpress-get-post-images-and-the_post_thumbnail-caption/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 23:11:40 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=391</guid>
		<description><![CDATA[Before the_post_thumbnail was available, here is how I would fetch an array of images that were attached to a post in wordpress: &#60;?php $images = &#38;get_children&#40;'post_type=attachment&#38;post_mime_type=image&#38;orderby=menu_order&#38;order=ASC&#38;post_parent='.$post-&#62;ID&#41;; if &#40;$images&#41;: $image = current&#40;$images&#41;; $imageData = wp_get_attachment_image_src&#40;$image-&#62;ID&#41;; ?&#62; &#60;img src=&#34;&#60;?php echo $imageData&#91;0&#93; ?&#62;&#34; alt=&#34;&#60;?php the_title&#40;&#41; ?&#62;&#34; /&#62; &#60;?php endif ?&#62; &#60;!-- image title: $image-&#62;post_title, caption: $image-&#62;post_excerpt, description: $image-&#62;post_content [...]]]></description>
			<content:encoded><![CDATA[<p>Before <code>the_post_thumbnail</code> was available, here is how I would fetch an array of images that were attached to a post in wordpress:<br />
<span id="more-391"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">&lt;?php</span> <span class="re0">$images</span> <span class="sy0">=</span> <span class="sy0">&amp;</span>get_children<span class="br0">&#40;</span><span class="st_h">'post_type=attachment&amp;post_mime_type=image&amp;orderby=menu_order&amp;order=ASC&amp;post_parent='</span><span class="sy0">.</span><span class="re0">$post</span><span class="sy0">-&gt;</span><span class="me1">ID</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$images</span><span class="br0">&#41;</span><span class="sy0">:</span>
    <span class="re0">$image</span> <span class="sy0">=</span> <span class="kw3">current</span><span class="br0">&#40;</span><span class="re0">$images</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="re0">$imageData</span> <span class="sy0">=</span> wp_get_attachment_image_src<span class="br0">&#40;</span><span class="re0">$image</span><span class="sy0">-&gt;</span><span class="me1">ID</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="sy1">?&gt;</span>
    &lt;img src=&quot;<span class="kw2">&lt;?php</span> <span class="kw1">echo</span> <span class="re0">$imageData</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="sy1">?&gt;</span>&quot; alt=&quot;<span class="kw2">&lt;?php</span> the_title<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">?&gt;</span>&quot; /&gt;
    <span class="kw2">&lt;?php</span> <span class="kw1">endif</span> <span class="sy1">?&gt;</span>
&lt;!-- image title: $image-&gt;post_title, caption: $image-&gt;post_excerpt, description: $image-&gt;post_content --&gt;</pre></div></div>

<p>Usually we&#8217;d use this just to pull out the first image attachment to a post and use this in a special place in our template. Now that there is built-in post thumbnail support, we wanted to use this feature but also still have the ability to display the selected thumbnail&#8217;s caption information. <code>the_post_thumbnail</code> only returns the image tag, so here is our custom filter (inside our template&#8217;s functions.php file) that adds our caption:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">function</span> monahans_thumbnail_caption<span class="br0">&#40;</span><span class="re0">$html</span><span class="sy0">,</span> <span class="re0">$post_id</span><span class="sy0">,</span> <span class="re0">$post_thumbnail_id</span><span class="sy0">,</span> <span class="re0">$size</span><span class="sy0">,</span> <span class="re0">$attr</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
  <span class="re0">$attachment</span> <span class="sy0">=&amp;</span> get_post<span class="br0">&#40;</span><span class="re0">$post_thumbnail_id</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="co1">// post_title =&gt; image title</span>
  <span class="co1">// post_excerpt =&gt; image caption</span>
  <span class="co1">// post_content =&gt; image description</span>
&nbsp;
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_excerpt</span> <span class="sy0">||</span> <span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_content</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$html</span> <span class="sy0">.=</span> <span class="st_h">'&lt;p class=&quot;thumbcaption&quot;&gt;'</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_excerpt</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="re0">$html</span> <span class="sy0">.=</span> <span class="st_h">'&lt;span class=&quot;captitle&quot;&gt;'</span><span class="sy0">.</span><span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_excerpt</span><span class="sy0">.</span><span class="st_h">'&lt;/span&gt; '</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="re0">$html</span> <span class="sy0">.=</span> <span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_content</span><span class="sy0">.</span><span class="st_h">'&lt;/p&gt;'</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">return</span> <span class="re0">$html</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
add_action<span class="br0">&#40;</span><span class="st_h">'post_thumbnail_html'</span><span class="sy0">,</span> <span class="st_h">'monahans_thumbnail_caption'</span><span class="sy0">,</span> <span class="kw4">null</span><span class="sy0">,</span> <span class="nu0">5</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>The result of this filter is now anytime we call <code>the_post_thumbnail</code> in our template, the html will come back with our image caption, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/02/12/wordpress-get-post-images-and-the_post_thumbnail-caption/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

