<?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>Not Related &#187; WordPress</title>
	<atom:link href="http://notrelated.com/category/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://notrelated.com</link>
	<description>Look at the title and make a guess</description>
	<lastBuildDate>Mon, 23 Apr 2012 20:41:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Improve Your Media Library&#8217;s Drill-down</title>
		<link>http://notrelated.com/wordpress/2011/improve-your-media-librarys-drill-down</link>
		<comments>http://notrelated.com/wordpress/2011/improve-your-media-librarys-drill-down#comments</comments>
		<pubDate>Sun, 13 Mar 2011 19:04:05 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=608</guid>
		<description><![CDATA[Between this blog and my portfolio site, I deal with a lot of media files. They&#8217;re usually images, and, fortunately, WordPress offers a drill-down for this by default. However, I also often upload PDFs and ZIPs, neither of which are supported by default for search narrowing. Although I&#8217;m working on a more elegant solution, you [...]]]></description>
			<content:encoded><![CDATA[<p>Between this blog and my portfolio site, I deal with a lot of media files. They&#8217;re usually images, and, fortunately, WordPress offers a drill-down for this by default. However, I also often upload PDFs and ZIPs, neither of which are supported by default for search narrowing. Although I&#8217;m working on a more elegant solution, you can get the code for the first incarnation after the vid.<span id="more-608"></span></p>
<div class="aligncenter"><object width="480" width="320"><param name="movie" value="http://www.youtube.com/v/wK7tq7L0N8E?fs=1&amp;hl=en_US" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="480" height="390" src="http://www.youtube.com/v/wK7tq7L0N8E?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<p>Go to your Admin Panel, then Appearance -&gt; Editor -&gt; Theme Functions. At the bottom of the file, add this code.</p>
<pre class="ln-"><code class="php">function modify_post_mime_types($post_mime_types) {
	$post_mime_types['application/pdf'] = array(
							__('PDFs'),
							__('Manage PDFs'),
							_n_noop('PDFs (%s)', 'PDFs (%s)')
							);

	$post_mime_types['application/zip'] = array(
							__('Zips'),
							__('Manage Zips'),
							_n_noop('Zips (%s)', 'Zips (%s)')
							);
	return $post_mime_types;
}

add_filter('post_mime_types', 'modify_post_mime_types');</code></pre>
<div id="attachment_620" class="wp-caption aligncenter" style="width: 455px"><img class="size-full wp-image-620" style="margin: 10px 0;" title="media-library-hackz" src="http://notrelated.com/wp-content/uploads/2011/03/media-library-hackz.jpg" alt="" width="445" height="111" /><p class="wp-caption-text">This is what you get.</p></div>
<p>(Hattip to the <a href="http://wordpress.org/support/topic/filter-media-library-by-file-type" target="_blank">WP support forums</a> for the original code).</p>
<p>So, let&#8217;s break that code down. <em>application/pdf </em>and <em>application/zip</em> are the mime types of the files I wanted. You could, however, drop in <em>any</em> <a href="http://www.webmaster-toolkit.com/mime-types.shtml" target="_blank">mime type</a> that you use frequently. After that, you need to replace <em>PDFs/ZIPs</em> with whatever you want to use to denote that file type. For example, if you want a tab for documents.</p>
<pre class="ln-"><code class="php">$post_mime_types['application/doc'] = array(
						__('Docs'),
						__('Manage Docs'),
						_n_noop('Docs (%s)', 'Docs (%s)')
						);</code></pre>
<p>WordPress will also allow a wild-card mime type search. In essence, that&#8217;s all the image/video/audio tabs are. The image tab matches image/*, for example. So, you can create a forth option that applies to &#8220;application&#8221; &#8211; unfortunately, pretty much everything that is not audio, video or image falls under that category. That option will result in a list that displays docs, PDFs, archives and anything else that matches application/*.</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2011/improve-your-media-librarys-drill-down/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Give WordPress a Cookie</title>
		<link>http://notrelated.com/wordpress/2011/give-wordpress-a-cookie</link>
		<comments>http://notrelated.com/wordpress/2011/give-wordpress-a-cookie#comments</comments>
		<pubDate>Tue, 18 Jan 2011 03:16:56 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[core spelunking]]></category>
		<category><![CDATA[wp cookies]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=562</guid>
		<description><![CDATA[In the process of working on a little side project (which shall be revealed shortly!) I found a need to set a cookie. I don&#8217;t think I&#8217;ve ever had to do it before, but it seemed simple enough. Until it didn&#8217;t work. Off to Google! There I found this tip from Scratch99.com on properly setting [...]]]></description>
			<content:encoded><![CDATA[<p>In the process of working on a little side project (which shall be revealed shortly!) I found a need to set a cookie. I don&#8217;t think I&#8217;ve ever had to do it before, but it seemed simple enough. Until it didn&#8217;t work. Off to Google! There I found this tip from <a href="http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/" target="_blank">Scratch99.com</a> on properly setting the site path, which doesn&#8217;t appear to work with WordPress 3.0.4 (or I may just be an idiot). I was a bit disappointed, but it gave me a good excuse to go spelunking through the core.<br />
<span id="more-562"></span></p>
<p>As always, this yields wonderful, fun things that make my life easier. WordPress has a constant that defines the site path, specifically for cookies. Ironically, this is named <em>SITECOOKIEPATH</em>.</p>
<p>Without more blabbering, here&#8217;s the code. Enjoy. =)</p>
<pre class="ln-"><code class="php">setcookie("your-cookie-name", 1, time()+3600, SITECOOKIEPATH);</code></pre>
<p>I&#8217;m using this to see if an ad has already been displayed to a user in the recent past. If you&#8217;re planning something similar, here&#8217;s how it will work out.</p>
<pre class="ln-"><code class="php">if(!isset($_COOKIE['your-cookie-name'])) {
	// do some PHP stuff here
	setcookie("your-cookie-name", 1, time()+3600, SITECOOKIEPATH);
}</code></pre>
<p><em>Here&#8217;s the <a href="http://php.net/manual/en/function.setcookie.php" target="_blank">PHP.net info on setting cookies</a>, if you&#8217;re unfamiliar with the process or just enjoy reading technical documentation.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2011/give-wordpress-a-cookie/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HELP! I broke my WordPress installation! (Part 1 of ???)</title>
		<link>http://notrelated.com/wordpress/2010/help-i-broke-my-wordpress-installation-part-1-of</link>
		<comments>http://notrelated.com/wordpress/2010/help-i-broke-my-wordpress-installation-part-1-of#comments</comments>
		<pubDate>Sun, 26 Sep 2010 07:06:48 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[break]]></category>
		<category><![CDATA[home url]]></category>
		<category><![CDATA[site url]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=507</guid>
		<description><![CDATA[Without a doubt, the most common reason why your WordPress installation suddenly stopped working is...you tried to change the home page. Yes, that's it. Although, you probably already knew that, since you're reading this. Here's what [probably] happened, here's what should have happened, and here's how you fix it.]]></description>
			<content:encoded><![CDATA[<p>Oh, WordPress, is there any way in which people <em>can&#8217;t</em> break you? I love you dearly, but sometimes, you&#8217;re a real pain in the ass.</p>
<p>Without a doubt, the <em>most common</em> reason why your WordPress installation suddenly stopped working is&#8230;you tried to change the home page. Yes, that&#8217;s it. Although, you probably already knew that, since you&#8217;re reading this. Here&#8217;s what [probably] happened, here&#8217;s what should have happened, and here&#8217;s how you fix it.<span id="more-507"></span></p>
<p>You [probably] decided you wanted your blog to show up at some nifty, pretty URL. The straight-up URL wasn&#8217;t cutting it. You wanted /home or /start or /owmystomachlining.</p>
<ol>
<li>You created a new Page &#8211; Ow My Stomach Lining</li>
<li>You went to the new page &#8211; http://myblog.com/owmystomachlining/ &#8211; and saw it working. w00t!</li>
<li>You went to Settings -&gt; General and changed <em>WordPress address (URL)</em> to that URL up there. Booo.</li>
</ol>
<p>Here&#8217;s what you should have done. <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory" target="_blank">Giving WordPress Its Own Directory</a>. I will not reiterate what&#8217;s written, I will only say go there, read that and do it.</p>
<p>The problem you now have is that the <em>WordPress Address</em> is supposed to be reflective of the <em>actual location of the files</em>. Now when WP starts up, it&#8217;s looking for something where it doesn&#8217;t exist. Woops.</p>
<p>Here&#8217;s how you fix it.</p>
<ol>
<li>Either you (or someone capable, should you not be) must open phpMyAdmin.</li>
<li>Have them to go the wp_options table.</li>
<li>Make sure the keys &#8216;home&#8217; and &#8216;siteurl&#8217; match the <em>actual location</em> of the WP files (usually, your URL)</li>
<li>Save, test, repeat if necessary.</li>
</ol>
<p>Part 2 of ??? will come when I find more common ways of breaking WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/help-i-broke-my-wordpress-installation-part-1-of/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: Difference between &#8220;trash&#8221; and &#8220;delete&#8221; functions</title>
		<link>http://notrelated.com/wordpress/2010/wordpress-difference-between-trash-and-delete-functions</link>
		<comments>http://notrelated.com/wordpress/2010/wordpress-difference-between-trash-and-delete-functions#comments</comments>
		<pubDate>Sun, 19 Sep 2010 15:32:57 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[update it]]></category>
		<category><![CDATA[version 3]]></category>
		<category><![CDATA[wp_delete_post]]></category>
		<category><![CDATA[wp_trash_post]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=496</guid>
		<description><![CDATA[WordPress has two native functions for removing posts. The traditional function, wp_delete_post, originated back in the day and has been used for a long while by post-related plugins. A second function, wp_trash_post, was added in version 2.9. Here's a short explanation.]]></description>
			<content:encoded><![CDATA[<p>WordPress has two native functions for removing posts. The traditional function, <em>wp_delete_post</em>, originated back in the day and has been used for a long while by post-related plugins. A second function, <em>wp_trash_post</em>, was added in version 2.9. Here&#8217;s a short explanation.<span id="more-496"></span></p>
<blockquote>
<pre>wp_delete_post( POSTID, TRUE );
// TRUE|FALSE: Bypass trash. Defaults to FALSE.</pre>
<pre>wp_trash_post( POSTID );</pre>
</blockquote>
<p>In version 3, WordPress peeps let out a sigh of relief with the advent of <em>custom post types</em>. No longer would we need to use custom fields to denote a special type of post! Unfortunately, the old school method of removal, <em>wp_delete_post</em>, isn&#8217;t equipped to handle custom post types.</p>
<blockquote>
<pre>wp_delete_post('399', FALSE);</pre>
</blockquote>
<p>This example will immediately trash whatever 399 is linked to&#8230;assuming it&#8217;s a standard post or page. <em>wp_delete_post</em> makes a determination when it runs: if the ID doesn&#8217;t belong to a post or a page, then it&#8217;s removed. If it&#8217;s a custom post, tough cookies, it&#8217;s insta-deleted, totally bypassing the trash.</p>
<p>The workaround is to use the newer function, <em>wp_trash_post</em>. This just accepts a post ID, and doesn&#8217;t particularly care about what type of entry it is. It simply changes the status to trash. If you give it something not trash worthy, and your data disappears into the database ether, that&#8217;s your problem.</p>
<p>Upshot: Unless you want to immediately, permanently delete the data, use <em>wp_trash_post</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/wordpress-difference-between-trash-and-delete-functions/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>wp-PrettyPhoto: Height, width and iFrame issue solved!</title>
		<link>http://notrelated.com/wordpress/2010/wp-prettyphoto-height-width-and-iframe-issue-solved</link>
		<comments>http://notrelated.com/wordpress/2010/wp-prettyphoto-height-width-and-iframe-issue-solved#comments</comments>
		<pubDate>Fri, 03 Sep 2010 05:09:36 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[lightbox]]></category>
		<category><![CDATA[width]]></category>
		<category><![CDATA[wp-prettyphoto]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=401</guid>
		<description><![CDATA[I was trying to get my first customer for the BigFishGames plugin for WordPress up and running when we ran into an issue about iFrames. His theme wasn&#8217;t large enough to accommodate the game&#8217;s frame, so he requested a lightbox. Being a jQuery dummy, I ran to wp-prettyPhoto for help. But, it didn&#8217;t work. =( [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to get my first customer for the <a title="Shameless self endorsement" href="http://wpplugins.com/plugin/192/arcadepress-big-fish-games" target="_blank">BigFishGames plugin for WordPress</a> up and running when we ran into an issue about iFrames. His theme wasn&#8217;t large enough to accommodate the game&#8217;s frame, so he requested a lightbox. Being a jQuery dummy, I ran to <a href="http://wordpress.org/extend/plugins/wp-prettyphoto/" target="_blank">wp-prettyPhoto</a> for help.</p>
<p>But, it didn&#8217;t work. =(</p>
<p>Oh, it opened it in a lightbox. But the height and width parameters weren&#8217;t working. According to the documentation, to use an iFrame you simply append</p>
<pre>?iframe=true&amp;width=[theWidth]&amp;height=[theHeight]
</pre>
<p>Seems straight forward, but it wasn&#8217;t working. I tried the obvious &#8211; should I add &#8220;px&#8221;? How about &#8220;pixel&#8221;? Change around width and height? Then I tried the support forum, saw several other people asking the same question and no reponse. (Get to the point, Becky.)</p>
<p>Go into admin-&gt;settings-&gt;WP-prettyPhoto and uncheck <em><label for="wppp_resize">Allow the prettyPhoto box to be resizeable</label>. </em>Problem solved. Have a nice day. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/wp-prettyphoto-height-width-and-iframe-issue-solved/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wrong Thumbnail Size! Onoes!</title>
		<link>http://notrelated.com/wordpress/2010/wrong-thumbnail-size-onoes</link>
		<comments>http://notrelated.com/wordpress/2010/wrong-thumbnail-size-onoes#comments</comments>
		<pubDate>Thu, 17 Jun 2010 02:33:08 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[cropping]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[settings]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=355</guid>
		<description><![CDATA[I&#8217;ve been having a conundrum with the company blog as of late. When I upload an image for a thumbnail, it works properly as long as I don&#8217;t use the built-in thumbnail capabilities. Assigning it to the thumbnail results in an oddly cropped image that looks entirely wrong. Fortunately, a few minutes of spelunking in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having a conundrum with the company blog as of late. When I upload an image for a thumbnail, it works properly as long as I don&#8217;t use the built-in thumbnail capabilities. Assigning it to the thumbnail results in an oddly cropped image that looks entirely wrong.</p>
<p>Fortunately, a few minutes of spelunking in the settings resulted in the Media options. If you&#8217;re having the same problem, visit -&gt;Settings-&gt;Media and unclick &#8220;Crop thumbnail to exact&#8230;&#8221; You can also control the default thumbnail size. I&#8217;m a bit amazed that the problem went on for so long before I found this (obvious!) solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/wrong-thumbnail-size-onoes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting WordPress to Run Automatic Updates on Ubuntu</title>
		<link>http://notrelated.com/wordpress/2010/getting-wordpress-to-run-automatic-updates-on-ubuntu</link>
		<comments>http://notrelated.com/wordpress/2010/getting-wordpress-to-run-automatic-updates-on-ubuntu#comments</comments>
		<pubDate>Wed, 21 Apr 2010 14:55:27 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ftp connection information]]></category>
		<category><![CDATA[plugin install]]></category>
		<category><![CDATA[wordpress update]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=336</guid>
		<description><![CDATA[I am not a Linux person. I like Windows. It does things for me and removes my need to think about what&#8217;s going on. Unfortunately, when my pretty little Dell decided to die a slow, excruciating death, I had no choice but to run Ubuntu on my husband&#8217;s craptastic spare HP laptop. Long story short, [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a Linux person. I like Windows. It does things for me and removes my need to think about what&#8217;s going on. Unfortunately, when my pretty little Dell decided to die a slow, excruciating death, I had no choice but to run Ubuntu on my husband&#8217;s craptastic spare HP laptop.<span id="more-336"></span></p>
<p>Long story short, working with Ubuntu was a pain, especially when it came to local WordPress development. In the most recent versions of WordPress, they&#8217;ve implemented an extra security feature. If the user running Apache isn&#8217;t the same as the user that owns the directory, you need to enter FTP connection information. And even if you do enter information (assuming you have it) it won&#8217;t work. <!--more--></p>
<blockquote><p>Note that your files all need to be owned by the user under which your Apache server executes, or you will receive a dialog box asking for &#8220;connection information,&#8221; and you will find that no matter what you enter, it won&#8217;t work. [<a href="http://codex.wordpress.org/Updating_WordPress" target="_blank">WordPress Codex</a>]</p></blockquote>
<p>What&#8217;s a Windows loving girl stuck in Linux hell to do? The first step is to nag her husband. The second step is to start screwing around with directory ownership until something works.</p>
<p>To turn off the godforsaken FTP connection information dialog, all you need to do is</p>
<ol>
<li>Open Terminal. (Applications -&gt; Accessories -&gt; Terminal)</li>
<li>Navigate to the folder directly above your troublesome WordPress installation. (<em>cd /var/www/some/other/directory</em>)</li>
<li>Give Apache ownership of the directory. (<em>sudo chown -R www-data.yourusername DirectoryName</em>)</li>
<li>Enter your password.</li>
</ol>
<p>Now, go back to your WordPress admin panel. Try running an automatic update on your installation or a plug-in, or install a new plug-in automatically. If all goes according to plan, you should see the beautiful successful installation screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/getting-wordpress-to-run-automatic-updates-on-ubuntu/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>5 Best Practices for WordPress Developers</title>
		<link>http://notrelated.com/wordpress/2010/5-best-practices-for-wordpress-developers</link>
		<comments>http://notrelated.com/wordpress/2010/5-best-practices-for-wordpress-developers#comments</comments>
		<pubDate>Fri, 19 Mar 2010 07:17:22 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[short tag]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=69</guid>
		<description><![CDATA[In a recent search for a WordPress chat plugin, I came across several &#8220;best practice&#8221; violations. Sometimes, ignoring best practices just gives future developers a headache. In other cases, it results in a inexplicable parse errors or PHP printing onto the user&#8217;s page. The issues are almost always due to internal server configuration. Just like [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent search for a WordPress chat plugin, I came across several &#8220;best practice&#8221; violations. Sometimes, ignoring best practices just gives future developers a headache. In other cases, it results in a inexplicable parse errors or PHP printing onto the user&#8217;s page.</p>
<p>The issues are almost always due to internal server configuration. Just like HTML and CSS, you should follow best practices in PHP to ensure compatibility on any server and save you &#8211; and your users &#8211; some trouble.</p>
<h3><span id="more-69"></span>Use only Long Tags</h3>
<blockquote><p>&lt;? echo(&#8220;Foo!&#8221;); ?&gt;</p></blockquote>
<p>For some reason, at some point in the past, someone decided short tags were a good idea. This is, without a doubt, the simplest fix of them all. In your <em>php.ini</em> file, there&#8217;s an option named <em>short_open_tag</em>. If you&#8217;re running a local server, you might have this option <em>on</em> and you might be able to get away with using it.</p>
<p>Most web hosts have the option off. The notes accompanying the option in <em>php.ini</em> tell you to keep it off.</p>
<blockquote><p>For portable, redistributable code, be sure not to use short tags.</p></blockquote>
<p>The fix is beautifully simple. Always open your PHP statements with <em>&lt;?php</em> instead of <em>&lt;?</em>. You&#8217;ll never have a problem with short tag compatibility.</p>
<h3>Don&#8217;t Close PHP</h3>
<p>While not as dramatic as the short tag fix, sometimes ending a PHP file with a closing <em>?&gt;</em> can cause header errors. Once you end the PHP block, everything else is considered output. If you&#8217;ve next document sends headers, then you&#8217;ll get beautiful, infuriating <em>Headers already sent</em> errors. By leaving the block open, you don&#8217;t need to worry about the possible white space disturbing the headers for the next function.</p>
<p>There are exceptions to this. In a WordPress theme, for example, you should always close PHP blocks. Since you can never be sure that the subsequent template start with PHP and not HTML, it&#8217;s best to close them all and meticulously remove lines afterward.</p>
<h3>Be Selective with Your Echo Statements</h3>
<p>There&#8217;s no graceful way to approach the issue of outputting HTML or JavaScript from a PHP function, especially if you need to echo PHP in the middle of the HTML (as in the WordPress Loop). You have three options</p>
<ol>
<li>Temporarily exit PHP for straight HTML and echo PHP in the middle.</li>
<li>Echo HTML lines and denote PHP in the middle.</li>
<li>Echo giant chunks of HTML and denote PHP as needed.</li>
</ol>
<p>You should [almost] never use the third option. It&#8217;s messy, error prone and, depending on the code, can cause apostrophe matching issues. I cry a little when I see this option used for a plug-in&#8217;s JavaScript. Bonus best practice: put JavaScript in its own file and include that.</p>
<p>To determine whether you should use the first or second option, consider the composition of the line(s). If you have more HTML than PHP and just need to echo a variable or three, you should opt for the first. However, if you have lots of PHP &#8211; functions, ternary operators, loops, etc. &#8211; you&#8217;re best off using the second.</p>
<h3>Use Functions</h3>
<p>When you&#8217;re making major overhauls to a WordPress (or any OS software) template, the temptation is to throw it in for easy access later. You wrote it, you know what it is, no problem, right?</p>
<p>Always assume that you won&#8217;t be the first, last and only person to ever touch the code. Maybe next week your brother-in-law&#8217;s cousin&#8217;s son will ask if you can start blogging with you. Or something breaks and you need to hire a coder to fix it. Or you get an offer for mad cash and sell it to retire in Zimbabwe.</p>
<p>If you add functionality that requires you to dedicate more than a single line to PHP,  you absolutely must a) put it in a function, b) put that function in the <em>template functions</em> file and c) give the function a really obvious name. And, of course, you really have to</p>
<h3>Comment Your Code [obligatory reminder]</h3>
<p>Way back when, while learning how to drive, my Dad used to joke that I should never let the other guy know what I was doing. If you&#8217;ve ever been rear-ended because you forgot to turn on your blinker, you&#8217;ll know what a really bad idea this is.</p>
<p>The single worst thing about working with someone else&#8217;s code is a complete lack of comments. I don&#8217;t look for dissertations on the value of their selected approach, but it would be nice if they&#8217;d let me know what they&#8217;re doing.</p>
<p>At bare minimum, you should comment each function. Let future developers know what the function does. If you use a relatively obscure native WordPress function, add a comment with its file name and line number, the Codex URL or a short blurb on what it is.</p>
<p><em>Sidesparks</em>, a chat plugin, gives very helpful comments.<em> </em></p>
<blockquote><p>/*<br />
* This will generate a Sidesparks Textlink with the specified link element<br />
* it will either use get_the_tags() in case it returns an array, else the title<br />
*/<br />
function generateSidesparksLink($link, $print = true) {&#8230;</p></blockquote>
<p><em>MyScorePresenter,</em> a plugin for flash games, gives less helpful comments.</p>
<blockquote><p>/*<br />
* @brief Expand Score data<br />
*/<br />
function myscore_expand_template($template, $score_result, $score_name) {</p></blockquote>
<p>See the difference? <em>Sidesparks</em> tells me exactly what the function does. <em>MyScorePresenter</em> gives me no context or instructions.  It actually doesn&#8217;t matter at this point which plugin has the &#8220;better&#8221; code. All that matters is that in one, I can figure out what a function does without reading the whole thing or wading through code.</p>
<p>There&#8217;s a bonus here for you: If you comment your code really well, you&#8217;re less likely to receive complaints such as &#8220;I installed it and my page turned white when I clicked <em>x</em>.&#8221; Instead, you might receive something like, &#8220;I kept getting a white page after clicking <em>x</em>, so I found the function that handles <em>x</em> in file <em>y</em> on line <em>z </em>and did some magic fix you can see in the new version that I attached.&#8221;</p>
<hr />
<p><em>Do you find the lightbulb icon to be extremely awesome? I also did and was quite tickled to find it. You can download it &#8211; for free! &#8211; along with the rest of the </em>Sienna<em> icon pack from </em><a title="Web Designer Depot - Sienna Icon Pack" href="http://www.webdesignerdepot.com/2009/03/200-free-exclusive-icons-siena/" target="_blank">Web Designer Depot</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/5-best-practices-for-wordpress-developers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turn WordPress into an RSS Reader</title>
		<link>http://notrelated.com/wordpress/2010/turn-wordpress-into-an-rss-reader</link>
		<comments>http://notrelated.com/wordpress/2010/turn-wordpress-into-an-rss-reader#comments</comments>
		<pubDate>Fri, 05 Mar 2010 15:06:36 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=29</guid>
		<description><![CDATA[Ah, the mighty RSS feed. Straight from your blog to your subscribers&#8217; readers. There are plenty of plugins for RSS feeds, like FeedWordPress, and WordPress also has a built in RSS widget that can display all sorts of goodies from blogroll feeds. Maybe you, like me, want to add a page dedicated to an RSS [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_30" class="wp-caption alignleft" style="width: 160px"><a href="http://notrelated.com/wp-content/uploads/2010/03/red-rss.jpg" rel="wp-prettyPhoto[g29]"><img class="size-thumbnail wp-image-30 " style="margin-top: 5px; margin-bottom: 5px;" title="Magenta RSS" src="http://notrelated.com/wp-content/uploads/2010/03/red-rss-150x150.jpg" alt="Turn WordPress into an RSS Reader" width="150" height="150" /></a><p class="wp-caption-text">Hacky? Possibly. WordPress can still load RSS feeds without a hitch.</p></div>
<p>Ah, the mighty RSS feed. Straight from your blog to your subscribers&#8217; readers. There are plenty of plugins for RSS feeds, like FeedWordPress, and WordPress also has a built in RSS widget that can display all sorts of goodies from blogroll feeds.</p>
<p>Maybe you, like me, want to add a page dedicated to an RSS feed. While you could definitely do this with any number of plugins, it&#8217;s easier to take advantage of a few native functions. Before you start, familiarize yourself with <a title="WordPress Codex Pages" href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates" target="_blank">WordPress&#8217; custom pages</a>.</p>
<p><span id="more-29"></span>In another post, I&#8217;ll go over using your Blogroll or another link category for the feed. Now, I&#8217;ll just cover taking the URL for an RSS feed and generating a list of posts.</p>
<blockquote><p>$url = &#8220;http://notrelated.com/feed&#8221;;<br />
$start = 0; // post to start with<br />
$end = 10; // post to end with<br />
$rss = fetch_feed($url); // get the feed<br />
foreach($rss-&gt;get_items($start, $end) AS $item) {<br />
$title = $item-&gt;get_title(); // post title<br />
$date = $item-&gt;get_date(&#8220;d.m.Y&#8221;); // post date, reference <a title="PHP.net date()" href="http://php.net/date" target="_blank">date()</a> for proper inputs<br />
$content = $item-&gt;get_content(); // post content<br />
$author = $item-&gt;get_author()-&gt;get_name(); // post author<br />
// now display is all in HTML<br />
}</p></blockquote>
<p>The retrieved feed can be displayed just like WordPress posts by using your Loop HTML. To see this in action, visit the<a title="Not Related: WordPress as RSS Reader Demo" href="http://notrelated.com/feeds-demo" target="_blank"> demo page</a>. You can also <a title="Turn WordPress into an RSS Reader" href="http://notrelated.com/wp-content/uploads/2010/03/page-feed.zip" target="_blank">grab the page</a> for your tweaking pleasure.</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/turn-wordpress-into-an-rss-reader/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Yesterday, Last Week, Last Month or Last Year in PHP</title>
		<link>http://notrelated.com/wordpress/2010/getting-yesterday-last-week-last-month-or-last-year-in-php</link>
		<comments>http://notrelated.com/wordpress/2010/getting-yesterday-last-week-last-month-or-last-year-in-php#comments</comments>
		<pubDate>Mon, 01 Mar 2010 05:55:39 +0000</pubDate>
		<dc:creator>Becky</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[strtotime]]></category>

		<guid isPermaLink="false">http://notrelated.com/?p=16</guid>
		<description><![CDATA[Most PHP functions have been talked to death on the Internet as a whole. I know this, and am approaching this post knowing this.

strtotime() is a function that, while widely discussed, is generally misunderstood. The application of strtotime() is far reaching. You can use it to get yesterday's date (even when today turns into tomorrow) or the date of next year (even when this year rolls over).]]></description>
			<content:encoded><![CDATA[<p><a title="PHP.net strtotime()" href="http://us.php.net/strtotime" target="_blank"><em>strtotime()</em></a> is a function that, while widely discussed, is generally misunderstood. The application of <em>strtotime()</em> is far reaching. You can use it to get yesterday&#8217;s date (even when today turns into tomorrow) or the date of next year (even when this year rolls over).<span id="more-16"></span></p>
<p><em>strtotime()</em> needs a phrase or string to convert into a UNIX timestamp. Usually, you&#8217;ll input something like <strong>-7 days</strong>, <strong>+20 days</strong> or <strong>02 May 2010</strong>. When you put in a string for a date, be aware that it must be in day-month-year format.</p>
<p>Easy example: you want to display yesterday&#8217;s date.</p>
<pre class="ln-"><code class="php">$yesterday = strtotime("-1 day");
echo("Yesterday was ".date("F d, Y", $yesterday));
// Yesterday was February 28, 2010</code></pre>
<p>How about something harder? Let&#8217;s say you have a blog and want to have a page just for the posts from the last seven days. You&#8217;ll need to format your dates a bit for WordPress to understand the request, using the <em>date()</em> function, but it&#8217;s easy enough.</p>
<pre class="ln-"><code class="php">$lastWeek = date("Y-m-d", strtotime("-7 days"));
$today = date("Y-m-d");</code></pre>
<p>This section sets the time boundaries. We want the (WordPress formatted) date for 7 days ago and the (WordPress formatted) date for today. The WordPress database formats dates as YYYY-MM-DD hh:mm:ss. Since we aren&#8217;t concerned about the hours, minutes or seconds, we&#8217;ll just format it for the earliest time one week ago, or 2010-02-21.</p>
<p>Now that we have the date, we can use the custom select query to select only the posts that fall in that date range. The WordPress Codex has a good primer on how to <a title="Displaying Posts Using a Custom Select Query" href="http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query" target="_blank">display posts using a custom select statement</a>. I&#8217;m basing the below query on that.</p>
<pre class="ln-"><code class="php">$querystr = "SELECT wposts.*
		FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta wpostmeta
		WHERE wposts.ID = wpostmeta.post_id
		AND wposts.post_date &gt;= '$lastWeek'
		AND wposts.post_date &lt;= '$today'
		AND wposts.post_type = 'post'
		ORDER BY wposts.post_date DESC;";
$posts = $wpdb-&gt;get_results($querystr, OBJECT);</code></pre>
<p>In the query, we&#8217;re telling WordPress to select the <em>post</em> and <em>post meta</em> data from the appropriate tables, to make sure the <em>ID</em>s of the entries match, and to limit the search based on date and <em>post_type</em>. <em>wposts.post_date</em> is the limiter for date. WordPress will look for any <em>post</em> that occurred between 7 days ago and today.</p>
<p>Now that we have the data, we can pass it into <a title="The Loop" href="http://codex.wordpress.org/The_Loop_in_Action" target="_blank">The Loop</a>, which is the WordPressy way to say we&#8217;re going to display the posts.</p>
<blockquote><p>get_header(); ?&gt;</p>
<p>&lt;div id=&#8221;content&#8221; role=&#8221;main&#8221;&gt;</p>
<p>&lt;?php</p>
<p>if($posts) {</p>
<p>foreach($posts AS $post) {</p>
<p>setup_postdata($post);</p>
<p>?&gt;</p>
<p>Your template&#8217;s HTML goes here</p></blockquote>
<p>Your template came with the Loop by default, in the form of <em>if (have_posts()) : while (have_posts()) : the_post();.</em> You&#8217;ll need to remove these lines. In the end, your front page should look similar to those, using the default Kubrick theme.</p>
<blockquote><p>&lt;?php</p>
<p>/**</p>
<p>* @package WordPress</p>
<p>* @subpackage Default_Theme</p>
<p>*/</p>
<p>$lastWeek = strtotime(&#8220;-7 day&#8221;);</p>
<p>$lastweek = date(&#8220;Y-m-d&#8221;, $lastWeek);</p>
<p>$today = date(&#8220;Y-m-d&#8221;);</p>
<p>$querystr = &#8221;</p>
<p>SELECT wposts.*</p>
<p>FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta wpostmeta</p>
<p>WHERE wposts.ID = wpostmeta.post_id</p>
<p>AND wposts.post_date &gt; &#8216;$lastWeek&#8217;</p>
<p>AND wposts.post_date &lt; &#8216;$today&#8217;</p>
<p>ORDER BY wposts.post_date DESC</p>
<p>&#8220;;</p>
<p>$posts = $wpdb-&gt;get_results($querystr, OBJECT);</p>
<p>get_header(); ?&gt;</p>
<p>&lt;div id=&#8221;content&#8221; role=&#8221;main&#8221;&gt;</p>
<p>&lt;?php</p>
<p>if($posts) {</p>
<p>foreach($posts AS $post) {</p>
<p>setup_postdata($post);</p>
<p>?&gt;</p>
<p>&lt;div &lt;?php post_class() ?&gt; id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221;&gt;</p>
<p>&lt;h2&gt;&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; rel=&#8221;bookmark&#8221; title=&#8221;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&#8221;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;</p>
<p>&lt;small&gt;&lt;?php the_time(&#8216;F jS, Y&#8217;) ?&gt; by &lt;?php the_author() ?&gt;&lt;/small&gt;</p>
<p>&lt;div&gt;</p>
<p>&lt;?php the_content(&#8216;Read the rest of this entry &amp;raquo;&#8217;); ?&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;p&gt;&lt;?php the_tags(&#8216;Tags: &#8216;, &#8216;, &#8216;, &#8216;&lt;br /&gt;&#8217;); ?&gt; Posted in &lt;?php the_category(&#8216;, &#8216;) ?&gt; | &lt;?php edit_post_link(&#8216;Edit&#8217;, &#8221;, &#8216; | &#8216;); ?&gt;  &lt;?php comments_popup_link(&#8216;No Comments &amp;#187;&#8217;, &#8217;1 Comment &amp;#187;&#8217;, &#8216;% Comments &amp;#187;&#8217;); ?&gt;&lt;/p&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;?php } ?&gt;</p>
<p>&lt;div&gt;</p>
<p>&lt;div&gt;&lt;?php next_posts_link(&#8216;&amp;laquo; Older Entries&#8217;) ?&gt;&lt;/div&gt;</p>
<p>&lt;div&gt;&lt;?php previous_posts_link(&#8216;Newer Entries &amp;raquo;&#8217;) ?&gt;&lt;/div&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;?php } else { ?&gt;</p>
<p>&lt;h2&gt;Not Found&lt;/h2&gt;</p>
<p>&lt;p&gt;Sorry, but you are looking for something that isn&#8217;t here.&lt;/p&gt;</p>
<p>&lt;?php get_search_form(); ?&gt;</p>
<p>&lt;?php } ?&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;?php get_sidebar(); ?&gt;</p>
<p>&lt;?php get_footer(); ?&gt;</p></blockquote>
<p>If you have any questions on or improvements for this code, let me know. And, as always, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://notrelated.com/wordpress/2010/getting-yesterday-last-week-last-month-or-last-year-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

