<?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>Michael Fields &#187; Theme Development</title>
	<atom:link href="http://wordpress.mfields.org/topics/theming/feed/" rel="self" type="application/rss+xml" />
	<link>http://wordpress.mfields.org</link>
	<description>I&#039;m a Theme Wrangler at Automattic! Rock!</description>
	<lastBuildDate>Tue, 27 Mar 2012 20:37:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Theming for the Masses</title>
		<link>http://wordpress.mfields.org/2011/theming-for-the-masses/</link>
		<comments>http://wordpress.mfields.org/2011/theming-for-the-masses/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 02:26:50 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=493</guid>
		<description><![CDATA[I just got word that my 2011 WordCamp Seattle presentation titled &#8220;Theming for the Masses&#8221; has been uploaded to wordpress.tv. While the video does not yet have an official page on the site, the video appears to be available and I&#8217;ve posted it here. Visit the official page on WordPress.tv! Coverage WordCamp Seattle by Morgan]]></description>
			<content:encoded><![CDATA[<p>I just got word that my 2011 WordCamp Seattle presentation titled &#8220;Theming for the Masses&#8221; has been uploaded to <a href="http://wordpress.tv/">wordpress.tv</a>. While the video does not yet have an official page on the site, the video appears to be available and I&#8217;ve posted it here.</p>
<p><span id="more-493"></span></p>
<div id="v-vyDjM104-1" class="video-player"><embed id="v-vyDjM104-1-video" src="http://s0.videopress.com/player.swf?v=1.03&amp;guid=vyDjM104&amp;isDynamicSeeking=true" type="application/x-shockwave-flash" width="700" height="392" title="Michael Fields: Theming for the Masses" wmode="direct" seamlesstabbing="true" allowfullscreen="true" allowscriptaccess="always" overstretch="true"></embed></div>
<p>Visit the official page on <a href="http://wordpress.tv/2011/08/17/michael-fields-theming-for-the-masses/">WordPress.tv</a>!</p>
<h2>Coverage</h2>
<ul>
<li><a href="http://alchemycs.com/2011/04/wordcamp-seattle/">WordCamp Seattle</a> by Morgan Kay of <a href="http://alchemycs.com/">Alchemy Computer Solutions</a></li>
<li><a href="http://theme.fm/2011/08/5-wordcamp-videos-you-should-have-watched-1979/">5 WordCamp Videos You Should Have Watched</a> by <a href="http://theme.fm/">theme.fm</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/theming-for-the-masses/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Template Parts for Custom Header Image.</title>
		<link>http://wordpress.mfields.org/2011/template-parts-for-custom-header-image/</link>
		<comments>http://wordpress.mfields.org/2011/template-parts-for-custom-header-image/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 02:43:05 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=485</guid>
		<description><![CDATA[Personally, I have never used a custom header image like those included in the TwentyTen and TwentyEleven themes. I think that they look great on other people&#8217;s sites, just not my own. Now, when you&#8217;re theming for the masses, you can pretty much toss all of your personal preferences out the window. In my opinion,]]></description>
			<content:encoded><![CDATA[<p>Personally, I have never used a custom header image like those included in the TwentyTen and TwentyEleven themes. I think that they look great on other people&#8217;s sites, just not my own. Now, when you&#8217;re <em>theming for the masses</em>, you can pretty much toss all of your personal preferences out the window. In my opinion, a good theme should be as flexible as possible. If WordPress provides an easy-to-implement solution, it&#8217;s usually a good idea to implement it! I recently came up with a neat solution to a design problem involving custom header images.</p>
<p><span id="more-485"></span></p>
<h2>The Problem</h2>
<p>The theme should look good with or without the header image. Now, I&#8217;ve pretty much fleshed out the design of my theme at this point and I really like how it looks without a header image. The design needs to be modified if this is going to work at all.</p>
<p>The most logical place to put the header would be where the site title, tagline and primary navigation menu are currently displayed. If I inject the image directly above this information the image looks great, but this pushes the site title down by 200 pixels and I really do not like this! Another idea would be to inject the image directly below the primary navigation menu. This doesn&#8217;t really look as nice in my opinion. The image seems to look best when it is at the top of my content div. What to do? I have some cake. I want to <em>&#8220;eat it too&#8221;</em>. I just hope that the cake is not a lie!</p>
<p>The solution that I decided on involves a little bit of logic that will move the title and tagline to the top of the screen if a header image has been defined by the user.</p>
<h2>Digging Into Some Code</h2>
<p>Here&#8217;s a simplified version of a cross-section of my header.php file before I got started. This code demonstrates how the theme should work when <strong>no header image</strong> is defined. <em>(Only the relevant parts of the template are included.)</em></p>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;wrap&quot;&gt;

	&lt;div id=&quot;page&quot;&gt;
	&lt;?php
		print '&lt;div id=&quot;site-title&quot;&gt;' . esc_html( get_bloginfo( 'blogname' ) ) . '&lt;/div&gt;';

		print '&lt;div id=&quot;tagline&quot;&gt;' . esc_html( get_bloginfo( 'description' ) ) . '&lt;/div&gt;';

		wp_nav_menu();
	?&gt;
</pre>
<p>To add a header image that looks acceptable to me, I would need to adjust the code to look like this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;wrap&quot;&gt;

	&lt;?php
	print '&lt;div id=&quot;site-title&quot;&gt;' . esc_html( get_bloginfo( 'blogname' ) ) . '&lt;/div&gt;';

	print '&lt;div id=&quot;tagline&quot;&gt;' . esc_html( get_bloginfo( 'description' ) ) . '&lt;/div&gt;';

	wp_nav_menu();
	?&gt;
	&lt;div id=&quot;page&quot;&gt;
	&lt;?php
		printf(
			'&lt;div id=&quot;header-image&quot;&gt;&lt;img src=&quot;%1$s&quot; width=&quot;%2$s&quot; height=&quot;%3$s&quot; alt=&quot;%4$s&quot;&gt;&lt;/div&gt;',
			esc_url( get_header_image() ),
			esc_attr( HEADER_IMAGE_WIDTH ),
			esc_attr( HEADER_IMAGE_HEIGHT ),
			esc_attr( get_bloginfo( 'blogname' ) )
		);
	?&gt;
</pre>
<p>Notice that all of the code inside the <code>#page</code> division has been moved outside and replaced by code to generate a header image.</p>
<p>Technically, I have two unique versions of header.php at this point which needs to be dealt with. But what to do? Initially, I thought that I could add an option to allow user to choose the header template to use. I could even make one of those fancy template selectors like I&#8217;ve seen in Genesis and the Options Framework. Depending on which template the user chose, I could load a different version of header.php. Maybe I could create a custom header-image.php to help facilitate this.</p>
<p>Whenever I get the idea of adding an option to a theme, I really take a look at the situation and ask myself if it is really necessary to do so. Most of the time I am able to talk myself out of it. This shown itself to be one of those times.</p>
<h2>Two Templates Bad. One Template Good.</h2>
<p>I decided that adding a bit of logic to one header.php would probably be a better solution. Here&#8217;s a breakdown:</p>
<h3>Get some info</h3>
<p>To make a decision we will need to know if the user has defined a header image. This is very easy to do. We will use WordPress core function <code>get_header_image()</code>. This function will return a url to the header image if one has been set. If not, it will return an empty string. The first step is to store this the return value of this function in a variable.</p>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;wrap&quot;&gt;

	&lt;?php
		$header_image = get_header_image();
	?&gt;
</pre>
<p>The next step is to determine whether the site title, tagline and primary navigation menu should be printed outside of the page division. We decided above that this should only happen if a header image has been defined by the user. We can easily test for a non-empty value:</p>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;wrap&quot;&gt;
&lt;?php
	$header_image = get_header_image();
	if ( ! empty( $header_image ) ) {
		print '&lt;div id=&quot;site-title&quot;&gt;' . esc_html( get_bloginfo( 'blogname' ) ) . '&lt;/div&gt;';

		print '&lt;div id=&quot;tagline&quot;&gt;' . esc_html( get_bloginfo( 'description' ) ) . '&lt;/div&gt;';

		wp_nav_menu();
	}
?&gt;
</pre>
<p>We&#8217;ll need to add a second conditional statement inside the page div as well. If the user has defined a header image we want to print the code to display that image. If not, we will need to print site title, tagline and primary navigation menu as they will not be printed above the page division when no header image has been defined by the user.</p>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;page&quot; class=&quot;contain&quot; role=&quot;document&quot;&gt;

&lt;?php
	if ( ! empty( $header_image ) ) {
		printf(
			'&lt;div id=&quot;header-image&quot;&gt;&lt;img src=&quot;%1$s&quot; width=&quot;%2$s&quot; height=&quot;%3$s&quot; alt=&quot;%4$s&quot;&gt;&lt;/div&gt;',
			esc_url( get_header_image() ),
			esc_attr( HEADER_IMAGE_WIDTH ),
			esc_attr( HEADER_IMAGE_HEIGHT ),
			esc_attr( get_bloginfo( 'blogname' ) )
		);
	}
	else {
		print '&lt;div id=&quot;site-title&quot;&gt;' . esc_html( get_bloginfo( 'blogname' ) ) . '&lt;/div&gt;';

		print '&lt;div id=&quot;tagline&quot;&gt;' . esc_html( get_bloginfo( 'description' ) ) . '&lt;/div&gt;';

		wp_nav_menu( apply_filters( 'nighthawk_menu_args_primary' );
	}
?&gt;
</pre>
<h2>Duplicate Code</h2>
<p>The logic works really well and provides the result that I was after, but unfortunately we have now duplicated the code the print the site title, tagline and navigation menu. The following code appears twice:</p>
<pre class="brush: php; title: ; notranslate">
print '&lt;div id=&quot;site-title&quot;&gt;' . esc_html( get_bloginfo( 'blogname' ) ) . '&lt;/div&gt;';

print '&lt;div id=&quot;tagline&quot;&gt;' . esc_html( get_bloginfo( 'description' ) ) . '&lt;/div&gt;';

wp_nav_menu();
</pre>
<p>Now, you may be thinking: &#8220;Come on Mike, it&#8217;s only three lines. What&#8217;s the big deal?&#8221;. Well, the actual code that I&#8217;m curreny using in the theme is much longer and looks a bit like this:</p>
<pre class="brush: php; title: ; notranslate">
if ( 0 != (int) get_theme_mod( 'nighthawk_display_site_title', 1 ) ) {
	$text = get_bloginfo( 'blogname' );
	if ( ! empty( $text ) ) {
		if ( ! is_front_page() || is_paged() ) {
			$text = '&lt;a href=&quot;' . esc_url( home_url() ) . '&quot;&gt;' . esc_html( $text ) . '&lt;/a&gt;';
		}
		print &quot;\n&quot; . '&lt;div id=&quot;site-title&quot;&gt;' . $text . '&lt;/div&gt;';
	}
}

if ( 0 != (int) get_theme_mod( 'nighthawk_display_tagline', 1 ) ) {
	$text = get_bloginfo( 'description' );
	if ( ! empty( $text ) ) {
		print &quot;\n&quot; . '&lt;div id=&quot;tagline&quot;&gt;' . esc_html( $text ) . '&lt;/div&gt;';
	}
}

wp_nav_menu( apply_filters( 'nighthawk_menu_args_primary', array(
	'container'      =&gt; 'div',
	'container_id'   =&gt; 'menu-top',
	'menu_class'     =&gt; 'menu',
	'theme_location' =&gt; 'primary',
	'depth'          =&gt; 1,
	'items_wrap'     =&gt; '&lt;ul id=&quot;%1$s&quot; class=&quot;%2$s&quot; role=&quot;navigation&quot;&gt;%3$s&lt;/ul&gt;',
	'fallback_cb'    =&gt; '_nighthawk_menu_dialog',
) ) );
</pre>
<p>It&#8217;s about 8 times as long. I really hate repeating myself when writing code, so I needed a solution to deal with this. The first thought I usually have is to bundle it into a function and then call the function twice. This solves the problem of repeated code, but introduces another issue. It&#8217;s a <abbr title="pain in the astronaut">PITA</abbr> to work around. This theme is going to be released to the public and one thing that I know for sure is that people will want to customize it. putting this code inside a function and hiding it away in functions.php is pretty easy to do, but if your users are not comfortable editing php files, chances are they are going to edit php files!</p>
<p>WordPress 3.0 introduced a function called get_template_part() which is a perfect alternative to creating theme functions. In my situation, it is the perfect solution. I moved the code above into a new file which I named top.php and then, in header.php, I included this new file with get_template_part(). My header.php now looks a bit like this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;wrap&quot;&gt;

	&lt;?php
		$header_image = get_header_image();
		if ( ! empty( $header_image ) ) {
			get_template_part( 'top', 'with-image' );
		}
	?&gt;

	&lt;div id=&quot;page&quot; class=&quot;contain&quot; role=&quot;document&quot;&gt;

	&lt;?php
		if ( empty( $header_image ) ) {
			get_template_part( 'top', 'no-image' );
		}
		else {
			printf(
				'&lt;div id=&quot;header-image&quot;&gt;&lt;img src=&quot;%1$s&quot; width=&quot;%2$s&quot; height=&quot;%3$s&quot; alt=&quot;%4$s&quot;&gt;&lt;/div&gt;',
				esc_url( $header_image ),
				esc_attr( HEADER_IMAGE_WIDTH ),
				esc_attr( HEADER_IMAGE_HEIGHT ),
				esc_attr( get_bloginfo( 'blogname' ) )
			);
		}
	?&gt;
</pre>
<p>Now, my header works as I would like it to, the code is as clean as possible and no code has been duplicated. Good times!</p>
<h2>Did You See What I Did There???</h2>
<p>If you look closely at each instance of get_template_part() you&#8217;ll see that I am passing the optional second parameter which allows you to give content to the template. Since we are using the file in two different contexts &#8211; &#8220;with an image&#8221; and &#8220;without an image&#8221; &#8211; it made sense to do this. &#8220;Why?&#8221; you ask. Well, this will give the most control possible the the end user. After they install my theme, if they need to customize it, they can easily create a child theme so that the original theme can be updated. If they decide that they do not like the code I have provided in top.php, all they need to do is create their own top.php in their child theme and modify it as they see fit. But creating top.php will change the code that displays both <strong>inside</strong> and <strong>outside</strong> the page division. This may or may not be desirable. What if they only want to change the code that displays <strong>outside</strong> the page division? Since we added context to the template part, this is relatively easy to do. A user can create a file named top-with-image.php. This file will only be called outside of the page division and the theme will use the original top.php when this template is called <strong>inside</strong> the page division.</p>
<h2>Questions? Concerns?</h2>
<p>Hope you enjoyed this! I know I was pretty excited when I came up with this solution. If you have anything to add to the conversation, please do so in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/template-parts-for-custom-header-image/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Theme: Nighthawk</title>
		<link>http://wordpress.mfields.org/2011/new-theme-nighthawk/</link>
		<comments>http://wordpress.mfields.org/2011/new-theme-nighthawk/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 12:45:22 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=409</guid>
		<description><![CDATA[Just switched out my theme again! Working on a new theme called Nighthawk. I was originally going to make Ghostbird 2 but, when all was said and done, I decided to make a different theme all together. Wish me luck!]]></description>
			<content:encoded><![CDATA[<p>Just switched out my theme again! Working on a new theme called <em>Nighthawk</em>. I was originally going to make <em>Ghostbird 2</em> but, when all was said and done, I decided to make a different theme all together. Wish me luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/new-theme-nighthawk/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Adding Context to Template Parts</title>
		<link>http://wordpress.mfields.org/2011/adding-context-to-template-parts/</link>
		<comments>http://wordpress.mfields.org/2011/adding-context-to-template-parts/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 10:03:58 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=408</guid>
		<description><![CDATA[One thing that I learned while creating the Ghostbird theme was that is is really important to take advantage of as many templates as possible. I have always said that &#8220;If I ever released a theme, it would only have one template file&#8221;. This is how Ghostbird was structured for about 90% of the time]]></description>
			<content:encoded><![CDATA[<p>One thing that I learned while creating the Ghostbird theme was that is is really important to take advantage of as many templates as possible. I have always said that <em>&#8220;If I ever released a theme, it would only have one template file&#8221;</em>. This is how Ghostbird was structured for about 90% of the time spent developing it. If you look at <a href="https://github.com/mfields/ghostbird/tree/0.9.1">version 0.9.1</a>, the only template file you will find is index.php. It was not until a very late stage that I saw the error of my ways and decided to add in other template files like search.php, 404.php and many more.</p>
<p><span id="more-408"></span></p>
<p>Once these files were in place I started to look very closely at them to see if there was anything that I could do to make <a href="http://codex.wordpress.org/Child_Themes">child theming</a> easier for users. I discovered that adding context to all template parts is a very easy thing to do and can allow child themes to modify small sections of a template.</p>
<h2>search.php</h2>
<p>This is one of the first template files that I added. I wanted to be sure to create a unique presentation of search results. I have always been bothered by themes whose search pages look exactly like their blog views. It was one of my goals to make my theme&#8217;s search results appear as if they were generated by a search engine. If you want to see what I came up with, you can <a href="http://wordpress.mfields.org/?s=taxonomy">search my site</a> and check it out.</p>
<p>Here is a very simplified version of a search.php template:</p>
<pre class="brush: php; title: ; notranslate">
get_header();
get_template_part( 'loop' );
get_sidebar();
get_footer();
</pre>
<p>It is relatively easy to override this template in a child theme by copying this file from the parent into the child and then modifying the contents.</p>
<p>But what if the user only needs to change something in the loop? What if they want to define a custom sidebar for use only in search views? It kinda seems silly to have to copy the entire template for such a task.</p>
<p>What I discovered is that all of the functions listed above can take a <var>$name</var> parameter.</p>
<pre class="brush: php; title: ; notranslate">
get_header( $name );
get_template_part( 'loop', $name );
get_sidebar( $name );
get_footer( $name );
</pre>
<p>For my theme&#8217;s search.php I used the string <code>search</code> for the <var>$name</var> parameter to give the appropriate context that the function is being used in.</p>
<pre class="brush: php; title: ; notranslate">
get_header( 'search' );
get_template_part( 'loop', 'search' );
get_sidebar( 'search' );
get_footer( 'search' );
</pre>
<p>Now that the context has been set for each template part function, it is easy to create any of the following files in the child theme to override a small section of the actual template:</p>
<ol>
<li>header-search.php</li>
<li>loop-search.php</li>
<li>sidebar-search.php</li>
<li>footer-search.php</li>
</ol>
<p>Once I discovered this trick, I wanted to apply it to all of my templates!</p>
<h2>single.php</h2>
<p>I&#8217;ve read many places before that single.php is the template used to display a single post. While this statement is not technically false, it doesn&#8217;t really tell the whole story. This file is actually responsible for displaying a single post of any public post_type (except for pages) that does not already have a designated template file. In other words, single.php is a &#8220;fallback&#8221; template for just about any query that asks for a single post.</p>
<p>Since single.php can be used to display any post_type, I decided that the <var>$name</var> or <em>context</em> parameter should use the post_type of the post instead of the name of the template file. My single.php looks something like this:</p>
<pre class="brush: php; title: ; notranslate">
/*
 * Capture the name of the queried post_type.
 *
 * Note: It's a good practice to prefix variables
 * with something that will not conflict with other
 * extensions. That is why I used $ghostbird_post_type
 * instead of $post_type here.
 */
$ghostbird_post_type = get_post_type();

/* Use the post_type as the context for each template part. */
get_header( $ghostbird_post_type );
get_template_part( 'loop', $ghostbird_post_type );
get_sidebar( $ghostbird_post_type );
get_footer( $ghostbird_post_type );
</pre>
<p>This setup allows for a great level of flexibility in child themes. Probably the most useful thing that can be done is to create a unique loop template for each registered post_type:</p>
<ol>
<li>loop-post.php</li>
<li>loop-person.php</li>
<li>loop-product.php</li>
<li>loop-bookmark.php</li>
</ol>
<p>Had the context been given as &#8220;single&#8221; (like I have seen many themes do) the only solution here would be to create a file named loop-single.php and then write conditional logic within the loop to render a different format depending on the post&#8217;s post_type.</p>
<h2>In Conclusion</h2>
<p>Adding context to template parts allows a user to affect only small parts of any given template. Some may argue that setting context in <code>get_header()</code> or <code>get_footer()</code> is only helpful is certain situations or <em>&#8220;edge cases&#8221;</em> and I totally agree! I feel that it important to allow for the greatest flexibility possible for all users. When all is said and done, this may only really help out a very small percentage of your users, but it is very easy to implement and makes extending your theme easier for those who take advantage of this functionality.</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/adding-context-to-template-parts/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Thoughts on Theme Documentation</title>
		<link>http://wordpress.mfields.org/2011/thoughts-on-theme-documentation/</link>
		<comments>http://wordpress.mfields.org/2011/thoughts-on-theme-documentation/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 02:23:09 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=404</guid>
		<description><![CDATA[If you&#8217;ve ever written a line of code before, I&#8217;m sure that the following scenario has reared it&#8217;s ugly head at some point in time. For one reason or another, you need to revisit code that you wrote in the past. Perhaps you remember writing something like this: But when you open the file and]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever written a line of code before, I&#8217;m sure that the following scenario has reared it&#8217;s ugly head at some point in time. For one reason or another, you need to revisit code that you wrote in the past. Perhaps you remember writing something like this:</p>
<p><span id="more-404"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
function super_awesome_mega_rad() {
	/*
		Beautiful code that solves all my problems.
		Good job buddy!
	*/
}
?&gt;
</pre>
<p>But when you open the file and scroll to the appropriate line you see something that looks like this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
function super_crappy_ultra_mess() {
	/*
		WTF?!?!?!
		Who wrote this crap?
		Oh, I did.
		I DID?!?!?!?!
		headdesk
               grumble ... grumble ...
	*/
}
?&gt;
</pre>
<p>Personally, this has happened to me more than once and the only thought that goes through my mind at times like these is &#8220;What the hell was I thinking?&#8221;. </p>
<p>This is a great question that demands to be answered! Providing inline documentation with your code is a great way to answer this question, not only for yourself, but everyone else who uses your theme.</p>
<p>While I was creating <a href="http://ghostbird.mfields.org/">Ghostbird</a>, the process of documentation became really, really clear to me and I would like to share my thoughts about the process I use to document my files.</p>
<p><a href="http://codex.wordpress.org/Inline_Documentation">WordPress core</a> uses PHPDoc style syntax to document core and I use it in all my plugins and themes. It&#8217;s good to keep things consistent! If you are new to phpDoc, you can read all about it here: <a href="http://manual.phpdoc.org/">http://manual.phpdoc.org/</a></p>
<p>In the scope of a theme, I found that two types of docBlocks were needed to provide the level of documentation necessary to communicate everything that I wanted. These include page-level docBlocks and function-level docBlocks.</p>
<h2>Page Level</h2>
<p>I felt that it was important to include a page level docBlock in every php file in my theme. This way I could clearly communicate the intended purpose of the file to the users. I used a subset of available phpDoc tags to accomplish this task. Here&#8217;s what I used in my theme&#8217;s header.php file:</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Header Template
 *
 * This file is responsible for generating the
 * top-most html for all public-facing views.
 * It's content is generated via core WordPress
 * functions as well as custom actions defined
 * in functions.php.
 *
 * Child themes are encouraged to work with the
 * actions defined herein to add or remove data
 * to/from the top of the template. In the event
 * that the html needs to be modified, this
 * template may be duplicated inside a child theme
 * and edited there. Please note the this file
 * leaves 2 html div tags open. Both of these tags
 * are properly closed in footer.php by default.
 *
 * @package      Ghostbird
 * @author       Michael Fields &lt;michael@mfields.org&gt;
 * @copyright    Copyright (c) 2011, Michael Fields
 * @license      http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since        1.0
 * @alter        1.1
 *
 * FUTURE RELEASE
 * @todo Add widget area. Intended for search form?
 */
</pre>
<h3>Title</h3>
<p>More times than not, I just used the name of the file with the extension removed.</dd>
<h3>Description</h3>
<p>In my opinion this is the most important part as it serves to communicate the intention of the file. To figure what to include in the description section for each template file, I did my best to answer the following questions:</p>
<ol>
<li>In which context is the template used?</li>
<li>How is the template best modified in a child theme?</li>
<li>Does the template use custom hooks?</li>
<li>Does the template leave any html tags open that are closed in another template?</li>
</ol>
<h3>Meta tags</h3>
<dl>
<dt>@package</dt>
<dd>This should be unique to your theme. In my opinion, only themes that ship with core should use the term &#8220;WordPress&#8221; here. Unless your theme is part of WordPress core, you should not use &#8220;WordPress&#8221; as your package name.</dd>
<dt>@author</dt>
<dd>This tag should include your name and, optionally, email address. In the event where multiple authors were responsible for writing code in the document, you can add multiple @author tags.</dd>
<dt>@copyright</dt>
<dd>This line should include the name of the copyright holder as well as the year the file was created.</dd>
<dt>@license</dt>
<dd>Used to communicate the license that your file is released under. It is a really good idea to include a link to the license as well.</dd>
<dt>@since</dt>
<dd>When was the file introduced into the package. This tag should reflect the version number of the theme.</dd>
<dt>@alter</dt>
<dd>This tag is not part of phpDoc. Quite honestly, I just pulled it out of thin air. I include this in all of my docBlocks so I can easily tell when the file was last modified.</dd>
</dl>
<p>While it may seem redundant to include all of this meta information in every single file, I feel that it&#8217;s better to be as explicit as possible. </p>
<h3>Todo tags</h3>
<p>The fourth and final section is totally optional but can be especially helpful. First of all, it will show users what you intend to do in the future. If you process all of your source code through a program like <a href="http://www.phpdoc.org/">phpDocumentor</a>, it will create a list of all todo items for your project &#8230; all in a single page! This can be really useful to see what needs to be done for the next version of your theme without having to dig through all the files.</p>
<h2>Function level.</h2>
<p>Function level docBlocks are used immediately before each function&#8217;s definition. While they are similar in appearance to page-level doc blocks, they serve a different purpose: To document the use of a single function. Here&#8217;s an example of a function from the Ghostbird theme:</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Append edit link to content.
 *
 * Certain post formats (aside, link and status)
 * do not display meta information at the bottom
 * of the entry box. While this makes them more
 * compact, it also removes the helpful edit link.
 * This function will add the link inside the_content
 * before wpautop() fires and after the [link] link
 * is appended.
 *
 * @param     string    Post content.
 * @return    string    Custom post content.
 *
 * @access    private
 * @since     1.1
 */
function _ghostbird_content_append_link_edit( $content ) {
	if ( is_single() ) {
		return $content;
	}
	$url = get_edit_post_link();
	if ( empty( $url ) ) {
		return $content;
	}
	$format = get_post_format();
	if ( in_array( $format, array( 'aside', 'link', 'status' ) ) ) {
		$content .= ' &lt;a class=&quot;post-edit-link auto-link&quot; href=&quot;' . esc_url( $url ) . '&quot; title=&quot;' . sprintf( esc_attr__( 'Edit this %1$s', 'ghostbird' ), ghostbird_post_label_singular() ) . '&quot;&gt;' . esc_html__( 'edit', 'ghostbird' ) . '&lt;/a&gt;';
	}
	return $content;
}
</pre>
<p>When documenting a function, I visually separate the docblock into four distinct sections. The first two sections are very similar to the page level docblocks and contain:</p>
<h3>Title</h3>
<p>Most of the time the name of the function (minus the unique prefix) works well here. I try to make this as short as possible.</p>
<h3>Description</h3>
<p>Quite possibly the most important part. In my opinion, this section should clearly state the <strong>intention</strong> of the function. Why was it created? If the function is intended to be hooked into WordPress, it is probably a good idea to include this information as well. In the event that the function declares it own custom hooks, the description is the perfect place to let users know how they can customize the function without altering it. phpDoc supports the inclusion of simple html tags, one of which is <code>code</code>. In most of my recent projects, I&#8217;ll include mini tutorials complete with code examples which users can copy and paste into their child themes. There is a lot that can be accomplished in the description of a function-level docBlock. I intentionally try to make them as long as possible.</p>
<h3>Input + Output</h3>
<p>This section is used whenever a function accepts input via parameter and/or returns a value. Two phpDoc Tags are used in this section:</p>
<dl>
<dt>@param</dt>
<dd>A line starting with the <code>@param</code> tag should be used to document each parameter accepted by the function. These lines should be listed in the order in which they are passed to the function. Each line should contain two pieces of information. The first defines the <em>type of variable</em> that the function expects. The second is meant to describe the data. So-called named arguments (a single associative array whose keys are recognized by the function) present an interesting challenge here. While I would agree that they should be represented in this section, I have not found a decent way to list all recognized keys here. Quite possibly the <em>cleanest</em> solution would be to list all recognized keys in the description.</dd>
<dt>@return</dt>
<dd>This tag is used to document that return value of the function. It uses the same format as the <code>@param</code> tag: Value 1 = data type &#038; Value 2 = description of the data. Not every function returns a value though and in cases like this I will set the data type to <code>void</code>. Sometimes I will use the &#8220;data description&#8221; section to document what the function does, but often I omit this if it is sufficiently explained in the description.</dd>
</dl>
<p>The last section that I always add includes the <code>@since</code> and <code>@alter</code> tags that I covered above as well as a new one: <code>@access</code>. If a function should not be directly used in the theme, I tag it as &#8220;private&#8221;. In cases where the user is free to place a function in a template file, I tag it as &#8220;public&#8221;.</p>
<p>And optional section for <code>@todo</code> can be added on the function level as well.</p>
<h2>Naming Conventions</h2>
<p>As you may already know, it is very important to create a unique prefix for all of your functions. This should be simple and unique. My theme is named &#8220;Ghostbird&#8221; so I used the prefix &#8220;ghostbird&#8221; at the start of all of my functions. I also started to adopt a naming convention that I picked up by reading core. WordPress has many &#8220;private&#8221; functions. While I don&#8217;t know the reason why each individual is marked as private, I do know that I shouldn&#8217;t really use them in my extensions. Most of these functions start with an underscore.</p>
<p>I think that this is a great idea! So I wanted to use it to. Looking over all of the custom functions that I created for my theme, I noticed that there were 3 specific types of functions existed:</p>
<ol>
<li>Template Tags</li>
<li>Hooks (action and filter callbacks).</li>
<li>Callbacks passed to core-defined template tags.</li>
</ol>
<p>I decided that <strong>Template Tags</strong> would be labeled as public meaning that these functions are free to be used in template files. Tagging a function as public also meant that the function could never be removed from the theme. </p>
<p><strong>Hooked Functions</strong> would definitely be tagged as private meaning that they should never ever be used anywhere. If end users follow instructions and do not use these functions, then they can easily be deleted in future releases.</p>
<p><strong>Callbacks</strong> are rather interesting as they embody properties of the previous two types. They need to be used directly in template files, but never alone. Functions of this type have been specifically designed to be passed to a core-defined template tag. I originally made the mistake of tagging functions of this type as &#8220;private&#8221; I now feel like they would better be tagged as &#8220;public&#8221;.</p>
<h2>In Conclusion</h2>
<p>While I do not use all of the tags supported by phpDoc, I have found that ones listed here are absolutely indispensable to provide useful documentation. This article represents my personal opinion and should be treated as such. I think that documentation is an integral part of any project and am always happy to see in when looking over source files. That being said, I do not feel comfortable defining rules for others to follow. Basically, I would prefer documentation in any form over no documentation at all.</p>
<p>Please let me know any thoughts in the comments section!</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/thoughts-on-theme-documentation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Scaling Images in IE8 with CSS max-width</title>
		<link>http://wordpress.mfields.org/2011/scaling-images-in-ie8-with-css-max-width/</link>
		<comments>http://wordpress.mfields.org/2011/scaling-images-in-ie8-with-css-max-width/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 23:29:15 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=399</guid>
		<description><![CDATA[Now that I&#8217;ve officially dropped support for IE6 in my work (a little late to the party? you ask &#8230; sure, I hope you saved some cake) it seemed like a good time to start introducing more CSS2 into my code. One of the problems that I faced was allowing an image to scale proportionally]]></description>
			<content:encoded><![CDATA[<p>Now that I&#8217;ve officially dropped support for IE6 in my work <em>(a little late to the party? you ask &#8230; sure, I hope you saved some cake)</em> it seemed like a good time to start introducing more CSS2 into my code. One of the problems that I faced was allowing an image to scale proportionally if it is larger than a predetermined size.</p>
<p><span id="more-399"></span></p>
<p>This was a suggestion of WordPress Theme Review Team member <a href="http://www.chipbennett.net/">Chip Bennett</a> as an alternative to just chopping the images short by setting the container&#8217;s <code>overflow</code> property to <code>auto</code>.</p>
<p>This is something that I would never have thought to do in IE6. Why? Well, while the image gets resized, it looks completely horrible Ever resize a .jpg <em>without</em> bicubic resampling? This is the result of scaling an image via css in IE6. See <a href="http://css-tricks.com/ie-fix-bicubic-scaling-for-images/">CSS Tricks</a> for a few screen captures from different browsers.</p>
<p>Here&#8217;s the code that should cause an image to scale proportionally in my content area:</p>
<pre class="brush: css; title: ; notranslate">
.entry img {
    max-width:615px
    height:auto;
}
</pre>
<p>Simple enough. If the image is greater than 615 pixels wide, set the width to 615 and the height will automatically adjust. Works in Gecko, works in Webkit &#8230; IE8? No dice! Well, until you put it into compatibility mode. Somehow. IE8 will get this right only if it is set to behave like IE7.</p>
<p>I scoured the internet for solutions. I even made it into page three of Google search results! I came across a similar issue in a forum and one of the answers given was to write javascript the would delete the <code>width</code> and <code>height</code> attributes from all image tags. Unfortunately, there was no code example so I came up with the following solution:</p>
<pre class="brush: jscript; title: ; notranslate">
var imgs, i, w;
var imgs = document.getElementsByTagName( 'img' );
for( i = 0; i &lt; imgs.length; i++ ) {
	w = imgs[i].getAttribute( 'width' );
	if ( 615 &lt; w ) {
		imgs[i].removeAttribute( 'width' );
		imgs[i].removeAttribute( 'height' );
	}
}
</pre>
<p>I put this code in my theme&#8217;s footer.php file and I was sure to tell it only to fire in IE8 with conditional tags:</p>
<pre class="brush: xml; title: ; notranslate">&lt;![endif]--&gt;&lt;!--[if IE 8]&gt;</pre>
<h2>What do you think?</h2>
<p>Have you faced this issue before? If so, did you handle it differently? Please share your solutions in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/scaling-images-in-ie8-with-css-max-width/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Introducing Ghostbird</title>
		<link>http://wordpress.mfields.org/2011/introducing-ghostbird/</link>
		<comments>http://wordpress.mfields.org/2011/introducing-ghostbird/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 00:20:40 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=375</guid>
		<description><![CDATA[Ghostbird is a free one-column theme for WordPress and it&#8217;s really, really close to being completed. There are more than a few things that I need to address before officially releasing it, but I wanted to get it out there and see what people think about what I have came up with. Here&#8217;s a link]]></description>
			<content:encoded><![CDATA[<p>Ghostbird is a free one-column theme for WordPress and it&#8217;s really, really close to being completed. There are more than a few things that I need to address before officially releasing it, but I wanted to get it out there and see what people think about what I have came up with. <span id="more-375"></span></p>
<p>Here&#8217;s a link to the latest development release:</p>
<p><a class="button github" href="https://github.com/mfields/ghostbird">Ghostbird <span>Development Version</span></a></p>
<div class="dialog notice">Ghostbird has been developed for WordPress 3.1.<br />
Installing this theme on any previous version is a <em>really</em>, <em>really</em> bad idea.</div>
<p>I would really appreciate comments on anything and everything that think about it. If you absolutely hate something, please let me know :) If I have done something horribly wrong, don&#8217;t just laugh at me, leave a comment below or on <a href="https://github.com/mfields/ghostbird/issues">Github</a> so that it can be addressed.</p>
<p>Here are a couple of sections of interest:</p>
<h2>Post Formats</h2>
<p><del datetime="2011-02-01T05:54:42+00:00">I&#8217;ve added support for all post formats except for links and would like to know your thoughts on how they are treated. A few notes:</del></p>
<ol>
<li><del datetime="2011-02-01T05:54:42+00:00"><strong>Image</strong> formats have a <a href="http://wordpress.mfields.org/2010/image-post-format-url-auto-discovery/">custom filter</a> which will allow you to enter only the url of an image. This <em>should</em> only work in case where the post_content contains only a url to an image.</del></li>
<li><del datetime="2011-02-01T05:54:42+00:00"><strong>Chat</strong> formats work best if you enclose the transcript inside a <code>pre</code> tag. This is the only way to trigger the custom filter.</del></li>
<li><del datetime="2011-02-01T05:54:42+00:00"><strong>Quote</strong> formats require the <em>quote</em> portion of the post to be wrapped in a <code>blockqoute</code> element.</del></li>
<li><del datetime="2011-02-01T05:54:42+00:00"><strong>Audio</strong> formats have no special styling. Outside of adding an icon (which I do not want to do) there is not much that I can really find to do with this format. The first thing that comes to mind is to find the first link/url to an audio file in the post_content and swap it with a fancy flash audio player. IMO this is best done through a 3rd party plugin and this is what I will suggest in the documentation.</del></li>
<li><strong>Titles</strong> &#8211; All formats can optionally display a title. If an author desires no title for a formatted post, they can leave the &#8220;title&#8221; section of the post blank.</li>
</ol>
<div id="post-format-update" class="dialog notice"><big>Update!</big></div>
<p>In hindsight adding support for all post formats seemed to be a bad idea. While it was fun to write some custom code to tweek their display, the over-all design of this theme does not support all post formats as I would like. While I&#8217;m nearing the end of development of Ghostbird it&#8217;s seemed like I only had two options:</p>
<ol>
<li>Change the entire visual to accommodate.</li>
<li>Drop the post formats that don&#8217;t fit.</li>
</ol>
<p>I decided to take the second route. I really like the visual aspect of the theme and, in my opinion, that&#8217;s more important than supporting all of the available post formats. It made sense to me to only support the post formats which looked and worked the best in the theme. Here&#8217;s the new list of supported formats:</p>
<ol>
<li>Aside</li>
<li>Gallery</li>
<li>Status</li>
<li>Standard</li>
</ol>
<h2>Custom Taxonomies and Post Types</h2>
<p>Support for custom post_types and taxonomies have been added directly into the theme. These elements should display well throughout the theme whether being referenced in metadata or displayed as archives. If you have an installation with custom post_types or taxonomies already defined it would be interesting to know you thoughts on how Ghostbird handles your data.</p>
<h2>Widgetized Areas</h2>
<p>Ghostbird currently has 4 widgetized areas. One that gets prepended to the the textarea in the contact form and 3 that display at the bottom of the <code>#page</code> div in a div with an id attribute of &#8220;widgets&#8221;. The bottom three work a bit differently than you might expect:</p>
<ul>
<li>If there are no widgets in any of the areas, no html should be printed for the the #widgets div.</li>
<li>If only one area has widgets, each widget should fill the horizontal area available. The only exception here is the calendar widget which should always be ~14em wide.</li>
<li>If two areas have widgets assigned then the left-most area will have a width of ~66% of the available horizontal space. The remaining 33% will be used for the second widgetized area.</li>
<li>In cases where all three areas have widgets, each area should be approximately 33% of the available horizontal space.</li>
<li>Although the widgets are numbered, the numbers to not define their position rather their order. If only areas 2 and 3 have widgets, they be be displayed in positions 1 and 2 in the html. Likewise if only area 3 has widgets, it will be seen as being in position #1 in the markup.</li>
</ul>
<p>I would really like to know your thoughts on this process. Do you see it breaking any custom widgets that you use?</p>
<h2>Intentionally Excluded</h2>
<ol>
<li><strong>SEO Stuff</strong> &#8211; Ghostbird contains no seo tools whatsoever. It is my opinion that this functionality is best provided via plugin and really does not belong in a theme. Ghostbird has been tested with Yoast&#8217;s <a href="http://yoast.com/wordpress/seo/">WordPress SEO Plugin</a>. Users are suggested to use this if they want full control over their SEO.</li>
<li><strong>Social Media Stuff</strong> &#8211; Ghostbird provides no built in method of interacting with <em>social networks</em>. There are plenty of plugins and users are urged to find an appropriate one for that meets their individual goals.</li>
</ol>
<h2>Did I miss anything?</h2>
<p>If you feel limited by the functionality of the Ghostbird theme, please sound off. I actually found myself deleting functions left and right the other day in hopes of simplifying the theme as much as possible. I also moved as much html as possible from the functions files into the template files which will hopefully aid in customizing the theme. I&#8217;m sure I probably overlooked a few things. Please let me know.</p>
<p>Other than that, Ghostbird should work just like any WordPress theme. There is a todo list in functions.php of things that I need to deal with. I would love it if you could download the theme and test with your own custom data. I feel like I&#8217;ve designed this thing about 5 or 6 separate times in the past month. This being said there might be code fragments here and there which make absolutely no sense at all.</p>
<h2>Things I plan on doing before release</h2>
<ol>
<li>Style global tables.</li>
<li><del datetime="2011-01-31T23:54:07+00:00">Revisit post formats.</del></li>
<li><del datetime="2011-01-31T10:09:02+00:00">Document everything in the Functions subpackage.</del></li>
<li>Test &#8220;big&#8221; tag across browsers &#8211; not sure about positioning here :)</li>
<li>Completely test and rewrite all examples in docs or remove if feeling lazy ;)</li>
<li><del>Excerpt filters for [...]</del></li>
<li>HTML validataion.</li>
<li>CSS validataion FWIW.</li>
<li>Add meta to search archives intro box.</li>
<li>Update and test style-editor.</li>
<li>Lighter fonts in Widgets.</li>
<li><del datetime="2011-02-09T20:10:03+00:00">Add Ghostbird settings page link to menu bar.</del></li>
<li>Style all features of the Syntax Highlighter plugin.</li>
<li><del datetime="2011-02-09T20:10:03+00:00">Add credit link in the footer.</del> <strong>Credit links are lame.</strong></li>
<li><del datetime="2011-02-09T20:10:03+00:00">Add donation link in the settings page.</del> <strong>Settings pages are lame</strong>.</li>
<li>Pretty-up the calendar widget.</li>
<li><del>Alpha for yellow-dots.png. Change name to halftone-small.png.</del></li>
<li><del datetime="2011-01-27T08:22:43+00:00">Ensure that all settings actually do something.</del></li>
<li><del datetime="2011-01-27T08:23:24+00:00">Less saturation on #author-box bg color.</del></li>
<li>Make dialog colors match new theme colors.</li>
</ol>
<h2>In Closing</h2>
<p>Version 0.9 is far from perfect and should not be used on live sites currently. I&#8217;m using it on mine and you can too, just don&#8217;t blame me if if the sun falls out of the sky :)</p>
<p>Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/introducing-ghostbird/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>What&#8217;s the biggest gripe you have with free WordPress themes?</title>
		<link>http://wordpress.mfields.org/2011/the-1-thing-you-hate-most-about-free-wordpress-themes/</link>
		<comments>http://wordpress.mfields.org/2011/the-1-thing-you-hate-most-about-free-wordpress-themes/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 22:44:04 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=363</guid>
		<description><![CDATA[The past couple of weeks, I&#8217;ve been working on a new theme for WordPress. I started redesigning this site and thought that it would be a good idea to code it really well and release it for free on WordPress.org. Then I learned about post formats and thought it would be a great idea to]]></description>
			<content:encoded><![CDATA[<p>The past couple of weeks, I&#8217;ve been working on a new theme for WordPress. I started redesigning this site and thought that it would be a good idea to code it really well and release it for free on <a href="http://wordpress.org/extend/themes/">WordPress.org</a>. Then I learned about post formats and thought it would be a great idea to incorporate this new functionality. <span id="more-363"></span></p>
<p>I&#8217;m just about finished and was wondering if anyone would want to help me out by letting me know the #1 thing that you have found frustrating when using free WordPress themes. Here&#8217;s mine:</p>
<blockquote><p>Lack of a unique titles across all views including custom post types, taxonomies and dated archive pages.
</p></blockquote>
<p>Just trying to cover as many bases as possible before I unleash this beast. Please leave a comment and let me know what <strong>NOT</strong> to do in my theme.</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/the-1-thing-you-hate-most-about-free-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Post Class for Posts with a &#8220;Read more&#8221; Link</title>
		<link>http://wordpress.mfields.org/2011/post-class-for-posts-with-a-read-more-link/</link>
		<comments>http://wordpress.mfields.org/2011/post-class-for-posts-with-a-read-more-link/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 00:51:12 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=360</guid>
		<description><![CDATA[You might find that it is important to style a post differently if it contains a Read More tag. If you find yourself in this scenario, it is rather easy to add a new class to the post using the post_class filter.]]></description>
			<content:encoded><![CDATA[<p>You might find that it is important to style a post differently if it contains a <a href="http://codex.wordpress.org/Customizing_the_Read_More">Read More</a> tag. If you find yourself in this scenario, it is rather easy to add a new class to the post using the <code>post_class</code> filter. <span id="more-360"></span></p>
<pre class="brush: php; title: ; notranslate">
function mfields_add_more_to_post_class( $classes ) {
	global $post;
	if ( ( is_archive() || is_home() ) &amp;&amp; false !== strpos( $post-&gt;post_content, '&lt;!--more--&gt;' ) &amp;&amp; ! in_array( 'more', $classes ) ) {
		$classes[] = 'more';
	}
	return $classes;
}
add_filter( 'post_class', 'mfields_add_more_to_post_class' );
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2011/post-class-for-posts-with-a-read-more-link/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Post Format: URL Auto Discovery</title>
		<link>http://wordpress.mfields.org/2010/image-post-format-url-auto-discovery/</link>
		<comments>http://wordpress.mfields.org/2010/image-post-format-url-auto-discovery/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 18:39:23 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=357</guid>
		<description><![CDATA[I&#8217;ve been geeking out with the new post formats feature in WordPress 3.1 for the past few weeks and I&#8217;ve decided to make a theme that supports all of the different formats. I&#8217;m just about have through them and I would like to share a neat trick that I used to enable users to post]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been geeking out with the new <a href="http://codex.wordpress.org/Post_Formats">post formats</a> feature in WordPress 3.1 for the past few weeks and I&#8217;ve decided to make a theme that supports all of the different formats. I&#8217;m just about have through them and I would like to share a neat trick that I used to enable users to post images a bit faster. <span id="more-357"></span></p>
<h2>The Image Post Format</h2>
<p>The WordPress Codex suggests that an image format is:</p>
<blockquote><p>A single image. The first &lt;img &gt; tag in the post should be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.</p></blockquote>
<p>This is pretty straight forward, and I was intrigued by the possibility of using the content to hold only a url to an image. If you could just copy and paste the url to an image into the post content, it would really speed up the workflow.</p>
<p>I won&#8217;t go into too many details but will say that this has passed all of my tests. If you&#8217;ve got a minute to test it out, please let me know your thoughts!</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/*
 * Filter content for posts having an image format.
 *
 * This filter will allow authors to post only a url to an image
 * in the post content and have the image display properly in the
 * theme as an img tag.
 *
 * An &quot;alt&quot; attribute will always be generated for each image. An
 * author can specify the value of the alt attribute by creating
 * a custom field with a key of &quot;mfields_alt&quot;. If no custom field
 * is available, an empty string will be used.
 *
 * The title attribute of the img tag will be populated by the value
 * produced by get_the_title(). In the event that there is no post
 * title available no title attribute will be printed.
 *
 * Child themes may customize the attributes generated for each image
 * by registering a custom function for the
 * 'mfields-image-format-attributes' filter. An example follows:
 *
 * This filter will add a class of &quot;mysite&quot; to all images hosted at
 * the same domain as WordPress is installed on.
 *
 * &lt;code&gt;
 * function mytheme_filter_image_format_attributes( $atts, $src ) {
 *     if ( false !== strstr( $src, site_url( '', 'http' ) ) ) {
 *         if ( isset( $atts['class'] ) ) {
 *             $atts['class'] = (array) $atts['class'];
 *         }
 *         $atts['class'][] = 'mysite';
 *     }
 *     return $atts;
 * }
 * add_filter( 'mfields-image-format-attributes', 'mytheme_filter_image_format_attributes', 10, 2 );
 * &lt;/code&gt;
 *
 * @param     string    Post content.
 * @return    string    HTML img tag if all conditions are met, unfiltered content otherwise.
 *
 * @since     1.0
 */
function mfields_filter_content_for_image_format( $content ) {
	if ( 'image' == get_post_format() ) {
		$src = esc_url( $content );
		$gis = @getimagesize( $src );
		if ( ! empty( $src ) &amp;&amp; is_array( $gis ) ) {
			$attributes = array();
			$post_id = get_the_ID();
			$title = get_the_title();
			$defaults = array(
				'alt'    =&gt; get_post_meta( $post_id, 'mfields_alt', true ),
				'width'  =&gt; $gis[0],
				'height' =&gt; $gis[1]
				);
			if ( ! empty( $title ) ) {
				$defaults['title'] = $title;
			}
			$filtered = apply_filters( 'mfields-image-format-attributes', $defaults, $src, $gis );
			$atts = array_merge( $defaults, $filtered );
			foreach( $atts as $name =&gt; $value ) {
				if ( in_array( $name, array( 'id', 'class', 'alt', 'title', 'height', 'width', 'longdesc', 'style' ) ) ) {
					if ( 'class' == $name &amp;&amp; is_array( $value ) ) {
						$value = implode( ' ', $value );
					}
					$attributes[] = $name . '=&quot;' . esc_attr( $value ) . '&quot;';
				}
			}
			$content = '&lt;img src=&quot;' . $src . '&quot; ' . implode( ' ', $attributes ) . '&gt;';
		}
	}
	return $content;
}
add_filter( 'the_content', 'mfields_filter_content_for_image_format', 0 );
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2010/image-post-format-url-auto-discovery/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

