<?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>Digging into WordPress &#187; classes</title>
	<atom:link href="http://digwp.com/tag/classes/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +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>Add Classes to post_class</title>
		<link>http://digwp.com/2010/03/add-classes-to-post_class/</link>
		<comments>http://digwp.com/2010/03/add-classes-to-post_class/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 21:04:45 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1567</guid>
		<description><![CDATA[The post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting: &#60;div &#60;?php post_class() ?&#62; id="post-&#60;?php the_ID(); ?&#62;"&#62; &#60;!-- Post stuff --&#62; &#60;/div&#62; I was in a circumstance where I wanted to add an additional class to what [...]]]></description>
			<content:encoded><![CDATA[<p>The post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting:</p>
<pre><code>&lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt;
   &lt;!-- Post stuff --&gt;
&lt;/div&gt;</code></pre>
<p>I was in a circumstance where I wanted to add an additional class to what that was outputting. My thought process went like this:</p>
<ol>
<li>Arg. I guess I&#8217;m going to have to write a function to filter the output of that function. Let&#8217;s begin the research.</li>
<li>Wait. I bet that function has an alternate that returns a string rather than echos it. I&#8217;ll just use that, and echo it out along with my own custom class.</li>
<li>Double wait. I bet those smart WordPress folks have thought of this&#8230;</li>
</ol>
<p><span id="more-1567"></span></p>
<h3>1. Filtering</h3>
<p>This kind of thing is generally beyond my comfort zone, but you&#8217;d basically write your own little function which takes in what the output would have been, add you own stuff to it, then return the new value.</p>
<p>Then call the new function with a filter in your functions.php file:</p>
<pre><code>add_filter('post_class','add_my_stuff');</code></pre>
<h3>2. Output exiting classes, then add yours</h3>
<p>Like most functions that echo stuff, there is a version that doesn&#8217;t echo stuff, in which &#8220;get_&#8221; prefaces the function name. I didn&#8217;t even have to look it up I just knew there would be. Since it&#8217;s a list, this function returns an array, so to output them, you&#8217;ll need to loop through the array:</p>
<pre><code>&lt;div class="&lt;?php $allClasses = get_post_class(); foreach ($allClasses as $class) { echo $class . " "; } ?&gt; group" id="post-&lt;?php the_ID(); ?&gt;"&gt;</code></pre>
<p>The cool part here is that is doesn&#8217;t add &#8220;class=&#8221; in the output, you can do that yourself, meaning that I can add my own classes after the output is finished.</p>
<h3>3. Built in&#8230;</h3>
<p>Of course, as it turns out, this is far easier than #2 made it out to be. To add additional classes, just pass them as a parameter!</p>
<pre><code>&lt;?php post_class('special'); ?&gt;</code></pre>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/add-classes-to-post_class/">Permalink</a> | <a href="http://digwp.com/2010/03/add-classes-to-post_class/#comments">2 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/add-classes-to-post_class/&title=Add Classes to post_class">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/classes/" rel="tag">classes</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/add-classes-to-post_class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

