<?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>The English Guy Web Design &#187; post_class</title>
	<atom:link href="http://www.theenglishguy.co.uk/tag/post_class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theenglishguy.co.uk</link>
	<description>Web Design, WordPress/Drupal blog design &#38; theming, SEO, css. xhtml, php, coldfusion, jquery and more...</description>
	<lastBuildDate>Tue, 31 Jan 2012 23:47:35 +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>post_class() and User Login</title>
		<link>http://www.theenglishguy.co.uk/2009/05/15/post_class-and-user-login/</link>
		<comments>http://www.theenglishguy.co.uk/2009/05/15/post_class-and-user-login/#comments</comments>
		<pubDate>Fri, 15 May 2009 13:43:27 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress theme]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[post_class]]></category>
		<category><![CDATA[user login]]></category>

		<guid isPermaLink="false">http://www.theenglishguy.co.uk/?p=1725</guid>
		<description><![CDATA[A scenario occurred recently with a theme that I have been developing where it needed to have each post section, [...]]]></description>
			<content:encoded><![CDATA[<p>A scenario occurred recently with a theme that I have been developing where it needed to have each post section, each div, to be given the classname of the author who wrote the post.</p>
<p>This could be useful for targetting certain users, <em>admin</em> for example.</p>
<p>Generally with WordPress templates you have <em>index.php</em> for the homepage, and <em>single.php</em> for each individual post. Some themes, including mine, separate this even further and have another template <em>post.php</em> included from the <em>single.php</em> template.</p>
<p>Regardless of whether further templates are used, the layout tends to be like this:</p>
<blockquote><p>
&lt;div class=&#8221;post&#8221;&gt;<br />
&nbsp;&lt;div class=&#8221;post-title&#8221;&gt;&lt;h2&gt;Title&lt;/h2&gt;&lt;/div&gt;<br />
&nbsp;&lt;div class=&#8221;post-content&#8221;&gt;Content Here&lt;/div&gt;<br />
&nbsp;&lt;div class=&#8221;post-bottom&#8221;&gt;Posted by &#8230;&lt;/div&gt;<br />
&lt;/div&gt;
</p></blockquote>
<p>With the introduction of WP-2.7 (Strayhorn), the new function <strong>post_class()</strong> was added, a very useful function. So this part&#8230;</p>
<blockquote><p>
&lt;div class=&#8221;post&#8221;&gt;
</p></blockquote>
<p>&#8230;now becomes&#8230;</p>
<blockquote><p>
&lt;div &lt;?php post_class(); ?&gt;&gt;
</p></blockquote>
<p>The post_class() function adds in all the necessary classes for each post, such as the category (if you post in the <em>all</em> category, the post_class() function adds the <em>category-all</em> class to the post div).</p>
<p>To modify this to add the name of the article&#8217;s author as a class to the div holding the post, you add in this bit of code and modify the post_class() as follows:</p>
<blockquote><p>
&lt;?php $curauth = get_userdata(intval($post-&gt;post_author)); ?&gt;</p>
<p>&lt;div &lt;?php post_class($curauth-&gt;user_login) ?&gt;&gt;
</p></blockquote>
<p>So that is very straightforward and from that point onwards the theme can customise posts for known/given users, such as admin, this might be useful on multi-author blogs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theenglishguy.co.uk/2009/05/15/post_class-and-user-login/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>post_class() and backwards compatibility</title>
		<link>http://www.theenglishguy.co.uk/2008/12/31/post_class-and-backwards-compatibility/</link>
		<comments>http://www.theenglishguy.co.uk/2008/12/31/post_class-and-backwards-compatibility/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 17:03:22 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress theme]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[post_class]]></category>
		<category><![CDATA[wordpress 2.7]]></category>

		<guid isPermaLink="false">http://www.theenglishguy.co.uk/?p=1579</guid>
		<description><![CDATA[There are several good guides to modifying your old WordPress (pre-2.7) themes to the new WordPress 2.7 and they cover [...]]]></description>
			<content:encoded><![CDATA[<p>There are several good guides to modifying your old WordPress (pre-2.7) themes to the new <strong>WordPress 2.7</strong> and they cover pretty much everything. One thing to remember though is that some of the new features and functions added in will only be present with <strong>WordPress 2.7</strong>.</p>
<p>This is the case with the new <em>post_class()</em> function which adds in class names for the post box. The <a href="http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Post_Classes">Codex</a> puts it like this:</p>
<blockquote cite="http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Post_Classes"><p>
The post_class() outputs the class=&#8221;whatever&#8221; piece for that div. This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds &#8220;sticky&#8221; for posts marked as sticky posts. These make it easy to style different parts of the theme in different ways.
</p></blockquote>
<p>Adding it the loop in the right place like this:</p>
<blockquote><p>
&lt;div id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221; &lt;?php post_class(); ?&gt;&gt;
</p></blockquote>
<p>This causes problems when you have a theme that you want to be backwards-compatible with prior versions of WordPress. So you need to change it to this:</p>
<blockquote><p>
&lt;?php if (function_exists(&#8220;post_class&#8221;)) { ?&gt;<br />
&nbsp;&nbsp;&lt;div id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221; &lt;?php post_class(); ?&gt;&gt;<br />
&lt;?php } else { ?&gt;<br />
&nbsp;&nbsp;&lt;div id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221;&gt;<br />
&lt;?php } ?&gt;
</p></blockquote>
<p>Now it works with previous WordPress versions!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theenglishguy.co.uk/2008/12/31/post_class-and-backwards-compatibility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

