<?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>bavotasan.com &#187; post</title>
	<atom:link href="http://bavotasan.com/tag/post/feed/" rel="self" type="application/rss+xml" />
	<link>http://bavotasan.com</link>
	<description>by c.bavota</description>
	<lastBuildDate>Tue, 07 Feb 2012 15:42:10 +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 to a URL Using cURL and PHP</title>
		<link>http://bavotasan.com/2011/post-url-using-curl-php/</link>
		<comments>http://bavotasan.com/2011/post-url-using-curl-php/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 17:48:16 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[$_POST]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3291</guid>
		<description><![CDATA[A client needed me to write a script that would collect information from their database and post it to a specific URL, just like it was being submitted by a form. I tried messing around with the idea and the solution I came up with required the cURL library for PHP. The script is pretty [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2011/03/post-curl-bg.jpg" alt="" title="post-curl-bg" width="550" height="200" class="aligncenter size-full wp-image-3295" />A client needed me to write a script that would collect information from their database and post it to a specific URL, just like it was being submitted by a form. I tried messing around with the idea and the solution I came up with required the <a href="http://php.net/manual/en/book.curl.php">cURL library</a> for PHP. </p>
<p>The script is pretty simple. First, let&#8217;s collect some data into an array:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">&quot;name&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;c.bavota&quot;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">&quot;website&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;http://bavotasan.com&quot;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">&quot;twitterID&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bavotasan&quot;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Now comes the function to post the data to an URL using cURL:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> post_to_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
      <span style="color: #000088;">$fields</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">;</span> 
   <span style="color: #009900;">&#125;</span>
   <span style="color: #990000;">rtrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>The function takes two parameters: the URL and the data array. If you need the returning results from the URL you&#8217;re posting to, you can remove that last <code>curl_setopt</code> line.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>With all that in place, now you can easily call the function, passing the two required parameters.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> post_to_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
      <span style="color: #000088;">$fields</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">;</span> 
   <span style="color: #009900;">&#125;</span>
   <span style="color: #990000;">rtrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">&quot;name&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;c.bavota&quot;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">&quot;website&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;http://bavotasan.com&quot;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">&quot;twitterID&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bavotasan&quot;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
post_to_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://yoursite.com/post-to-page.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>On the receiving end, you can treat it just like you would if you were using a form to post the information to that specific URL.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/post-url-using-curl-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Shorten Your Post Titles in WordPress</title>
		<link>http://bavotasan.com/2010/shorten-your-post-titles-in-wordpress/</link>
		<comments>http://bavotasan.com/2010/shorten-your-post-titles-in-wordpress/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 15:24:22 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[magazine]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[php tags]]></category>
		<category><![CDATA[pop]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[reason]]></category>
		<category><![CDATA[Slideshow]]></category>
		<category><![CDATA[title]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2542</guid>
		<description><![CDATA[This is not a function that you would need to use often, but I came across a reason to use it recently and I thought it might be a good idea to share it. All it does is limit the number of words in your title, just in case you don&#8217;t want it to wrap [...]]]></description>
			<content:encoded><![CDATA[<p>This is not a function that you would need to use often, but I came across a reason to use it recently and I thought it might be a good idea to share it. All it does is limit the number of words in your title, just in case you don&#8217;t want it to wrap onto a second line. I used it in the featured slideshow on <a href="http://themes.bavotasan.com/our-themes/premium-themes/magazine-premium/">Magazine Premium</a> since the size of the boxes is fixed.</p>
<p>Include this in your <code>functions.php</code> file between the PHP tags:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> short_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$after</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">array_pop</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$after</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$mytitle</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Then you can use it within the WordPress loop like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> short_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'...'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>If you would rather count by characters instead of just words, you can add this function to your <code>functions.php</code> file instead of the one above:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> short_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$after</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">array_pop</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$after</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$mytitle</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/shorten-your-post-titles-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Excluding Pages from WordPress Search</title>
		<link>http://bavotasan.com/2010/excluding-pages-from-wordpress-search/</link>
		<comments>http://bavotasan.com/2010/excluding-pages-from-wordpress-search/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 20:05:18 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[Pages]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[Search Query]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2508</guid>
		<description><![CDATA[When people visit my site and do a search, I assume they&#8217;re looking for results within my posts and not in any of my static pages. Too bad WordPress automatically searches through both. In order to exclude pages from the WordPress search, you need to add a small piece of code to the functions.php file. [...]]]></description>
			<content:encoded><![CDATA[<p>When people visit my site and do a search, I assume they&#8217;re looking for results within my posts and not in any of my static pages. Too bad WordPress automatically searches through both. In order to exclude pages from the WordPress search, you need to add a small piece of code to the <code>functions.php</code> file. I found a solution on <a href="http://www.wprecipes.com/how-to-exclude-posts-or-pages-from-search-results">WP Recipes</a> but I was not a fan of having to add all of my category IDs in order to make it work. So I decided to modify it a bit.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> SearchFilter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_search</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pre_get_posts'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'SearchFilter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>I forced it to just search for posts through setting the <code>post_type</code>. You can also make it do the opposite by setting the <code>post_type</code> to page.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/excluding-pages-from-wordpress-search/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Quick Function to Shorten the Post Title in WordPress</title>
		<link>http://bavotasan.com/2010/quick-function-shorten-post-title-wordpress/</link>
		<comments>http://bavotasan.com/2010/quick-function-shorten-post-title-wordpress/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 20:46:16 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[need]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[pop]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[reason]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1881</guid>
		<description><![CDATA[For some reason, a lot of people seem to be using extremely long post titles. I am a firm believer in making a title as precise as possible to make it easier on people who are trying to actually find your article. Sure, I guess you can throw in as many keywords as you want [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason, a lot of people seem to be using extremely long post titles. I am a firm believer in making a title as precise as possible to make it easier on people who are trying to actually find your article. Sure, I guess you can throw in as many keywords as you want in hopes that you might get more from Google, but I doubt that will really do anything for your site&#8217;s SEO.<br />
<span id="more-1881"></span><br />
In case you are one of those people who feel the need for extremely long post titles and you want to display them in places where they might not fit, here is a quick piece of code that you can add to your <code>functions.php</code> file.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> short_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$after</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">array_pop</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$after</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$mytitle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$mytitle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$mytitle</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>You can call the function like so:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">// short_title($after, $length)</span>
<span style="color: #b1b100;">echo</span> short_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'...'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>The above code will truncate your title at 10 words and add a trailing ellipsis.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/quick-function-shorten-post-title-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Check if a Page is a Child of Another Page in WordPress</title>
		<link>http://bavotasan.com/2009/check-if-a-page-is-a-child-of-another-page-in-wordpress/</link>
		<comments>http://bavotasan.com/2009/check-if-a-page-is-a-child-of-another-page-in-wordpress/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 17:11:26 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[Directory]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[Place]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1456</guid>
		<description><![CDATA[This post has been updated in &#8220;is_child() Conditional Function for WordPress&#8221;. WordPress has some default conditional tags that are really helpful when developing themes and plugins that need specific functions on specific pages. Strange enough though, there is no way to check if a page is a child of another page. This small function checks [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bit.ly/dOxWm7">This post has been updated in &#8220;is_child() Conditional Function for WordPress&#8221;.</a></p>
<p>WordPress has some default <a href="http://codex.wordpress.org/Conditional_Tags">conditional tags</a> that are really helpful when developing themes and plugins that need specific functions on specific pages. Strange enough though, there is no way to check if a page is a child of another page.<br />
<span id="more-1456"></span><br />
This small function checks the database to see if the page happens to have a parent page assigned to it. If so, then the function will return true.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_child<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pageID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #339933;">==</span><span style="color: #000088;">$pageID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
               <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Place the above code in your theme&#8217;s functions.php file, or create a functions.php file and place it in your theme&#8217;s directory. Then you can use the is_child() function anywhere in your theme. Your code would look something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_child<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">343</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;This is a child page of 'The Parent Page Title'.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/check-if-a-page-is-a-child-of-another-page-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Display a List of Upcoming Posts in WordPress</title>
		<link>http://bavotasan.com/2009/display-a-list-of-upcoming-posts-in-wordpress/</link>
		<comments>http://bavotasan.com/2009/display-a-list-of-upcoming-posts-in-wordpress/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 05:10:51 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ability]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Creating]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Wp]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1480</guid>
		<description><![CDATA[When you have completed a post in WordPress, you have the ability to save it as a draft, publish it immediately or schedule a future date when it will be published automatically. This is extremely helpful if you want to plan ahead or if you use your WP site for events. Creating a simple list [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2009/11/wordpress-logo-shine.jpg" alt="wordpress-logo-shine" title="wordpress-logo-shine" width="200" height="150" class="alignright size-full wp-image-1482" />When you have completed a post in WordPress, you have the ability to save it as a draft, publish it immediately or schedule a future date when it will be published automatically. This is extremely helpful if you want to plan ahead or if you use your WP site for events. Creating a simple list of upcoming posts lets your visitors know what they can look forward to and is pretty simple to do.<br />
<span id="more-1480"></span><br />
The following code can be placed in your sidebar on within any template.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$futurePosts</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$futurePosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'showposts=5&amp;post_status=future&amp;order=ASC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$futurePosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$futurePosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;ul&gt;
&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;br /&gt;&lt;small&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/small&gt;&lt;/li&gt;
&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;ul&gt;
 &lt;li&gt;No upcoming events.&lt;/li&gt;
&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>If you want to only display future posts from a specific category, you can add a <code>cat=$id</code> to the query like so:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$futurePosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'showposts=5&amp;post_status=future&amp;order=ASC&amp;cat=12'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Be sure to change the &#8220;12&#8243; to the category ID.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/display-a-list-of-upcoming-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Using jQuery to make an Expandable Code Box for WP-Syntax</title>
		<link>http://bavotasan.com/2009/using-jquery-to-make-an-expandable-code-box-for-wp-syntax/</link>
		<comments>http://bavotasan.com/2009/using-jquery-to-make-an-expandable-code-box-for-wp-syntax/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 17:43:00 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[background color]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[Chris Coyier]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[fan]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[highlighter]]></category>
		<category><![CDATA[horizontal]]></category>
		<category><![CDATA[hover]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[minor changes]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Plugin Code]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[Syntax Highlighter]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[var]]></category>
		<category><![CDATA[Width]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress plugin]]></category>
		<category><![CDATA[Wp]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1440</guid>
		<description><![CDATA[You may have noticed that I&#8217;m using a new syntax highlighter for my code snippets. I installed Ryan McGeary&#8216;s WordPress plugin WP-Syntax which uses GeSHi (Generic Syntax Highlighter), a simple highlighting class that supports multiple coding languages. It&#8217;s great but I&#8217;m not a fan of the horizontal scrollbar that appears if code extends past your [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2009/07/jquery.png" alt="jquery" title="jquery" width="200" height="150" class="alignright size-full wp-image-726" />You may have noticed that I&#8217;m using a new syntax highlighter for my code snippets. I installed <a href="http://ryan.mcgeary.org/">Ryan McGeary</a>&#8216;s WordPress plugin <a href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax</a> which uses <a href="http://qbnz.com/highlighter/">GeSHi</a> (Generic Syntax Highlighter), a simple highlighting class that supports multiple coding languages. It&#8217;s great but I&#8217;m not a fan of the horizontal scrollbar that appears if code extends past your site&#8217;s width. Instead, I decided to use <a href="http://jquery.com/">jQuery</a> to expand the box when you hover over it.<br />
<span id="more-1440"></span><br />
We need to make a few minor changes to the plugin code to get this to work. After you have downloaded, installed and activated the plugin, open up <code>wp-syntax.php</code> and go to line #113:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>113
114
115
116
117
118
119
120
121
122
123
124
125
126
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;table&gt;&lt;tr&gt;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>line_numbers<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> wp_syntax_line_numbers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>code<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$geshi</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parse_code</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>code<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$geshi</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parse_code</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We need to add a table to the second output.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">    if <span style="color: #00AA00;">&#40;</span>$line<span style="color: #00AA00;">&#41;</span>
    <span style="color: #00AA00;">&#123;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;table&gt;&lt;tr&gt;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>line_numbers<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> wp_syntax_line_numbers<span style="color: #00AA00;">&#40;</span>$code<span style="color: #00AA00;">,</span> $line<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>code<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> $geshi-<span style="color: #00AA00;">&gt;</span>parse_code<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    else
    <span style="color: #00AA00;">&#123;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&quot;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>code<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> $geshi-<span style="color: #00AA00;">&gt;</span>parse_code<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;/div&gt;&quot;</span><span style="color: #00AA00;">;</span>
        $output .<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Next we need to open up <code>wp-syntax.css</code> to change a few of the styles. Change this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.wp_syntax</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#100</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f9f9f9</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">silver</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1.5em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.wp_syntax</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#100</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f9f9f9</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">silver</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1.5em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">590px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>I put a fixed width of 590px because I have set that as the maximum width of my single posts.</p>
<p>Now comes the <a href="http://jquery.com">jQuery</a>. Open up your theme&#8217;s <code>header.php</code> file and add the following between  your &lt;head&gt; tags.:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;?php wp_enqueue_script(&quot;jquery&quot;); ?&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.wp_syntax&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> width <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> pad <span style="color: #339933;">=</span> width <span style="color: #339933;">+</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>width <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">590</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				zIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;100&quot;</span><span style="color: #339933;">,</span>
				position<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;relative&quot;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				width<span style="color: #339933;">:</span> pad <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				width<span style="color: #339933;">:</span> <span style="color: #CC0000;">590</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>What we are doing above is creating an effect that will only occur when you hover over the code box. It finds the width of the table and animates the expansion to the full width. When you hover out, the box returns to the fixed width of your post. Be sure that you set the two references to <em>590</em> to whatever you set your width to in the CSS.</p>
<p>Done and done!</p>
<p>To see this in action check out <a href="http://bavotasan.com/tutorials/how-to-create-a-twitter-feed-on-your-web-site/">How to Create a Twitter Feed on Your Web Site</a>.</p>
<p><strong>Resource</strong>: <a href="http://digwp.com/2009/07/making-an-expanding-code-box/">Making an Expanding Code Box by Chris Coyier</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/using-jquery-to-make-an-expandable-code-box-for-wp-syntax/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Display Random Posts in WordPress</title>
		<link>http://bavotasan.com/2009/display-random-posts-in-wordpress/</link>
		<comments>http://bavotasan.com/2009/display-random-posts-in-wordpress/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 17:16:23 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[category id]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Display]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Little Bit]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1384</guid>
		<description><![CDATA[I am working on a new WordPress site and I wanted to display a selection of random posts at the bottom of every page. It is pretty simple to do, but I also wanted to make sure that on single post pages, the current post would be excluded. That took a little bit more figuring [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a new WordPress site and I wanted to display a selection of random posts at the bottom of every page. It is pretty simple to do, but I also wanted to make sure that on single post pages, the current post would be excluded. That took a little bit more figuring out but I got it working.<br />
<span id="more-1384"></span><br />
Here is a quick piece of code to insert into your WordPress templates so that you can display a list of random posts, excluding the current post that is displayed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'orderby'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'rand'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'showposts'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'post__not_in'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postid</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;ul&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span>the_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span>the_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>You can always change the number of random posts displayed by increasing or decreasing the &#8216;showposts&#8217; variable. You can also make it category specific by adding a <code>'cat'=>24,</code> to the $args array, where &#8217;24&#8242; is the category ID.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/display-random-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Win a One-Year Subscription to Layers Magazine</title>
		<link>http://bavotasan.com/2009/win-a-one-year-subscription-to-layers-magazine/</link>
		<comments>http://bavotasan.com/2009/win-a-one-year-subscription-to-layers-magazine/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 19:08:53 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[Canada]]></category>
		<category><![CDATA[canada and the united states]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[designer]]></category>
		<category><![CDATA[everything]]></category>
		<category><![CDATA[issue]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[lot]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[magazine]]></category>
		<category><![CDATA[month]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[October]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[title]]></category>
		<category><![CDATA[trackback]]></category>
		<category><![CDATA[use]]></category>
		<category><![CDATA[Whole Lot]]></category>
		<category><![CDATA[Win]]></category>
		<category><![CDATA[winner]]></category>
		<category><![CDATA[Year]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1241</guid>
		<description><![CDATA[October is here and that means it&#8217;s time for another contest. This month I will be giving away a one-year subscription to Layers Magazine. For those who have never heard of Layers Magazine, it is the #1 how-to magazine for everything Adobe. Each issue features tutorials, reviews, designer inteviews and a whole lot more. To [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2009/10/layers.jpg" alt="layers" title="layers" width="300" height="216" class="alignright size-full wp-image-1242" />October is here and that means it&#8217;s time for another contest. This month I will be giving away a one-year subscription to <a href="http://www.layersmagazine.com/">Layers Magazine</a>. For those who have never heard of <a href="http://www.layersmagazine.com/">Layers Magazine</a>, it is the #1 how-to magazine for everything Adobe. Each issue features tutorials, reviews, designer inteviews and a whole lot more. To win a one-year subscription, all you need to do is link to this post on your site. It is as simple as that.<br />
<span id="more-1241"></span><br />
Just create your own link to this article or use the following code:</p>
<div class="sections">
<pre>
&lt;a href='http://bavotasan.com/articles/win-a-one-year-subscription-to-layers-magazine/' title='Win a One-Year Subscription to Layers Magazine'&gt;Win a One-Year Subscription to Layers Magazine&lt;/a&gt;</pre>
</div>
<p>On November 1st, 2009, I will randomly select a trackback and award the winner a one-year subscription to <a href="http://www.layersmagazine.com/">Layers Magazine</a>.</p>
<p><small>This contest is only open to residents of Canada and the United States. The winner will be contacted through their Web site on November 1st, 2009. Contest ends October 31st at 11:59pm.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/win-a-one-year-subscription-to-layers-magazine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom Template for Single Posts in WordPress</title>
		<link>http://bavotasan.com/2009/custom-template-for-single-posts-in-wordpress/</link>
		<comments>http://bavotasan.com/2009/custom-template-for-single-posts-in-wordpress/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 14:10:44 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Amp]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[category id]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[Default Theme]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[end]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[h2]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[look]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[raquo]]></category>
		<category><![CDATA[slug]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[trackback]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1225</guid>
		<description><![CDATA[If you take a look at the template hierarchy in WordPress, you will notice that you have the ability to create custom templates for different category pages by simply adding the category slug or id to the end of your filename. So category-articles.php will be called before category.php if you query the Articles category. But [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-1057" title="WordPress" src="http://bavotasan.com/wp-content/uploads/2009/08/wp.png" alt="WordPress" width="200" height="150" />If you take a look at the <a href="http://codex.wordpress.org/Template_Hierarchy">template hierarchy in WordPress</a>, you will notice that you have the ability to create custom templates for different category pages by simply adding the category slug or id to the end of your filename. So <code>category-articles.php</code> will be called before <code>category.php</code> if you query the <em>Articles</em> category. But what if you wanted to have a custom template for every post in the <em>Articles</em> category so that it displayed differently from posts in other categories. By default that can&#8217;t be done unless you do a little hacking.<br />
<span id="more-1225"></span><br />
Here is an easy way to create custom templates for single posts in WordPress.</p>
<p>First, we need to figure out the category id of the posts we want to customize. Open up your wp-admin and go to the Categories page. Click on the category you want and then take a look in the address bar. You should see something like this:</p>
<p><a class="highslide" href="http://bavotasan.com/wp-content/uploads/2009/09/catid.png"><img class="aligncenter size-medium wp-image-1226" title="catid" src="http://bavotasan.com/wp-content/uploads/2009/09/catid-570x26.png" alt="catid" width="570" height="26" /></a></p>
<p>The 32 at the end is your category id.</p>
<p>Now open up your <code>single.php</code> file and let&#8217;s make a few changes. I will use the <code>single.php</code> file from the Default theme as an example.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
* @package WordPress
* @subpackage Default_Theme
*/</span>
&nbsp;
get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div id=&quot;content&quot; role=&quot;main&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div&gt;
&lt;div&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> previous_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;laquo; %link'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&lt;div&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> next_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%link &amp;raquo;'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;div <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;h2&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
&nbsp;
&lt;div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p&gt;Read the rest of this entry &amp;raquo;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_link_pages<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'next_or_number'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'&lt;p&gt;Tags: '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;p&gt;
&lt;small&gt;
This entry was posted
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/* This is commented, because it requires a little adjusting sometimes.
You'll need to download this plugin, and follow the instructions:
http://binarybonsai.com/wordpress/time-since/ */</span>
<span style="color: #666666; font-style: italic;">/* $entry_datetime = abs(strtotime($post-&gt;post_date) - (60*120)); echo time_since($entry_datetime); echo ' ago'; */</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
on <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l, F jS, Y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> at <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
and is filed under <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>.
You can follow any responses to this entry through the <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_comments_feed_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RSS 2.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> feed.
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Both Comments and Pings are open ?&gt;</span>
You can <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#respond&quot;</span><span style="color: #339933;">&gt;</span>leave a response<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;,</span> or <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php trackback_url(); ?&gt;&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;trackback&quot;</span><span style="color: #339933;">&gt;</span>trackback<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> from your own site<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Only Pings are Open ?&gt;</span>
Responses are currently closed<span style="color: #339933;">,</span> but you can <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php trackback_url(); ?&gt; &quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;trackback&quot;</span><span style="color: #339933;">&gt;</span>trackback<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> from your own site<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Comments are open, Pings are not ?&gt;</span>
You can skip to the <span style="color: #990000;">end</span> and leave a response<span style="color: #339933;">.</span> Pinging is currently not allowed<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Neither Comments, nor Pings are open ?&gt;</span>
Both comments and pings are currently closed<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> edit_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Edit this entry'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/small&gt;
&lt;/p&gt;
&nbsp;
&lt;/div&gt;
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> comments_template<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;p&gt;Sorry, no posts matched your criteria.&lt;/p&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>To get this little hack to work all you need to do is add:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>in_category<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Custom Template for Single Posts in Category 32</span>
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'single-32.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>On line #1 and:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>74
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>All the way at the bottom.</p>
<p>So now your <code>single.php</code> file should look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>in_category<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'single-32.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
* @package WordPress
* @subpackage Default_Theme
*/</span>
&nbsp;
get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div id=&quot;content&quot; role=&quot;main&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div&gt;
&lt;div&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> previous_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;laquo; %link'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&lt;div&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> next_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%link &amp;raquo;'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;div <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;h2&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
&nbsp;
&lt;div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p&gt;Read the rest of this entry &amp;raquo;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_link_pages<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'next_or_number'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'&lt;p&gt;Tags: '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;p&gt;
&lt;small&gt;
This entry was posted
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/* This is commented, because it requires a little adjusting sometimes.
You'll need to download this plugin, and follow the instructions:
http://binarybonsai.com/wordpress/time-since/ */</span>
<span style="color: #666666; font-style: italic;">/* $entry_datetime = abs(strtotime($post-&gt;post_date) - (60*120)); echo time_since($entry_datetime); echo ' ago'; */</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
on <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l, F jS, Y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> at <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
and is filed under <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>.
You can follow any responses to this entry through the <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_comments_feed_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RSS 2.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> feed.
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Both Comments and Pings are open ?&gt;</span>
You can <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#respond&quot;</span><span style="color: #339933;">&gt;</span>leave a response<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;,</span> or <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php trackback_url(); ?&gt;&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;trackback&quot;</span><span style="color: #339933;">&gt;</span>trackback<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> from your own site<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Only Pings are Open ?&gt;</span>
Responses are currently closed<span style="color: #339933;">,</span> but you can <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php trackback_url(); ?&gt; &quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;trackback&quot;</span><span style="color: #339933;">&gt;</span>trackback<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> from your own site<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Comments are open, Pings are not ?&gt;</span>
You can skip to the <span style="color: #990000;">end</span> and leave a response<span style="color: #339933;">.</span> Pinging is currently not allowed<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>comments_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>pings_open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Neither Comments, nor Pings are open ?&gt;</span>
Both comments and pings are currently closed<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> edit_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Edit this entry'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/small&gt;
&lt;/p&gt;
&nbsp;
&lt;/div&gt;
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> comments_template<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;p&gt;Sorry, no posts matched your criteria.&lt;/p&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now all you need to do is create a file called <code>single-32.php</code> and add it to your theme. Code that file however you want your single page posts in category 32 to appear and you are done.</p>
<p>You can also use this hack if you want to create a custom template for a specific post. Just replace <code>in_category()</code> with <code>is_page()</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/custom-template-for-single-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

