<?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>WP Wizard &#187; WordPress Hacks</title>
	<atom:link href="http://wpwizard.net/category/wordpress-hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpwizard.net</link>
	<description>I ❤ WordPress</description>
	<lastBuildDate>Sat, 05 Mar 2011 12:30:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Remove «Comments are closed» message</title>
		<link>http://wpwizard.net/wordpress-hacks/remove-%c2%abcomments-are-closed%c2%bb-message/</link>
		<comments>http://wpwizard.net/wordpress-hacks/remove-%c2%abcomments-are-closed%c2%bb-message/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 21:16:18 +0000</pubDate>
		<dc:creator>Stian Andreassen</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stianandreassen.com/?p=605</guid>
		<description><![CDATA[Easily remove «Comments are closed» with a single line of code.]]></description>
			<content:encoded><![CDATA[<p>Getting annoyed with the «Comments are closed»-message on <strong>Posts</strong> and <strong>Pages</strong> where you have shut off the comment option? It’s easy to remove. Here’s how:<br />
<span id="more-605"></span><br />
Edit the relevant file(s) in your theme, usually <code>single.php</code> and <code>page.php</code>. </p>
<p>Find: </p>
<p><code>&lt;?php comments_template();  ?&gt;</code> </p>
<p>And replace with: </p>
<p><code>&lt;?php if('closed' != $post->comment_status) comments_template(); ?&gt;</code></p>
<p>That’s it – «Comments are closed» is history.</p>
<div class="shr-publisher-605"></div>]]></content:encoded>
			<wfw:commentRss>http://wpwizard.net/wordpress-hacks/remove-%c2%abcomments-are-closed%c2%bb-message/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Display related Posts</title>
		<link>http://wpwizard.net/wordpress-hacks/display-related-posts/</link>
		<comments>http://wpwizard.net/wordpress-hacks/display-related-posts/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:27:02 +0000</pubDate>
		<dc:creator>Stian Andreassen</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.stianandreassen.com/?p=198</guid>
		<description><![CDATA[Display related Posts by Tags or Category without a plugin - just a few lines of code is all that's needed.]]></description>
			<content:encoded><![CDATA[<p>There are many plugins that let you display related <strong>Posts</strong>. Some are obviously better than others – but you don&#8217;t really need a plugin to do the job. You can add some lines of code to your <strong>Template</strong>, which will display related <strong>Posts</strong> based on similar <strong>Tags</strong> or <strong>Categories</strong>.</p>
<p><span id="more-198"></span>I will show you two options; displaying related Posts based on either <strong>Tags</strong> or <strong>Categories</strong>. Put the code in your <code>single.php</code> where you want to display related <strong>Posts</strong>. Right above <code>&lt;?php comments_template(); ?&gt;</code> is probably the best place.</p>
<p>The following will display the five most recent <strong>Posts</strong> which share the same first <strong>Tag</strong> of the <strong>Post</strong>:</p>
<pre class="brush: php; title: ;">
&lt;?php
$tags = wp_get_post_tags($post-&gt;ID);
if ($tags) {
	$first_tag = $tags[0]-&gt;name;
	$args = array(
		'numberposts' =&gt; 5,
		'tag' =&gt; $first_tag,
		'exclude' =&gt; $post-&gt;ID
	);
	$related = get_posts($args);
	if($related) {
		echo &lt;div id=&quot;relatedposts&quot;&gt;';
		echo &lt;h4&gt;Related Posts&lt;/h4&gt;';
	  	echo&lt;ul&gt;';
		  foreach ( $related as $rel ):
			echo &lt;li&gt;&lt;a href=&quot;'. get_permalink($rel-&gt;ID) .'&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to '. $rel-&gt;post_title .'&quot;&gt;'. $rel-&gt;post_title .&lt;/a&gt;&lt;/li&gt;';
		  endforeach;
	    echo &lt;/ul&gt;';
	    echo &lt;/div&gt;';
 	 }
}
?&gt;
</pre>
<p>If you don&#8217;t use <strong>Tags</strong>, or simply just want to find related <strong>Posts</strong> based on <strong>Category</strong>, the following code will do that – displaying the five most recent <strong>Posts</strong> from the first <strong>Category</strong> of the <strong>Post</strong>.</p>
<pre class="brush: php; title: ;">
&lt;?php
$cats = get_the_category();
if ($cats) {
	$first_cat = $cats[0]-&gt;cat_ID;
	$args = array(
		'numberposts' =&gt; 5,
		'category' =&gt; $first_cat,
		'exclude' =&gt; $post-&gt;ID,
	);
	$related = get_posts($args);
	if($related) {
		echo '&lt;div id=&quot;relatedposts&quot;&gt;';
		echo '&lt;h4&gt;Related Posts&lt;/h4&gt;';
	  	echo'&lt;ul&gt;';
		  foreach ( $related as $rel ):
			echo '&lt;li&gt;&lt;a href=&quot;'. get_permalink($rel-&gt;ID) .'&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to '. $rel-&gt;post_title .'&quot;&gt;'. $rel-&gt;post_title .'&lt;/a&gt;&lt;/li&gt;';
		  endforeach;
	    echo '&lt;/ul&gt;';
	    echo '&lt;/div&gt;';
 	 }
}
?&gt;
</pre>
<p>The upshot of using this method, as opposed to a plugin, is that you have complete control and can display and style the related <strong>Posts</strong> as you see fit.</p>
<div class="shr-publisher-198"></div>]]></content:encoded>
			<wfw:commentRss>http://wpwizard.net/wordpress-hacks/display-related-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort Posts by date or title</title>
		<link>http://wpwizard.net/wordpress-hacks/sort-posts-by-date-or-title/</link>
		<comments>http://wpwizard.net/wordpress-hacks/sort-posts-by-date-or-title/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 07:12:38 +0000</pubDate>
		<dc:creator>Stian Andreassen</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[the Loop]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.stianandreassen.com/?p=165</guid>
		<description><![CDATA[By default WordPress sorts by date, but this can be changed with a single line of code to sort by title.]]></description>
			<content:encoded><![CDATA[<p>WordPress sorts <strong>Posts</strong> by date in descending order as default. But what if you want to order <strong>Posts</strong> by title? Say you have a <strong>Category</strong> where you archive movie reviews, and you want to sort this by title instead of by date. It&#8217;s easy to implement with a single line of code.</p>
<p><span id="more-165"></span>In the <code>category.php</code> of your <strong>Theme</strong> (if you don&#8217;t have a <code>category.php</code> you can duplicate <code>index.php</code> and rename it), add this line above <strong>the Loop</strong> (which usually starts with <code>&lt;?php if (have_posts()) : ?&gt;</code>):</p>
<pre class="brush: php; light: true; title: ;">&lt;?php query_posts('orderby=title&amp;amp;order=ASC'); ?&gt;</pre>
<p>You can extend this by adding links for which sort type you want. In your <code>category.php</code> add this where you want the links to appear:</p>
<pre class="brush: php; title: ;">
&lt;p&gt;
 Sort by:
 &lt;a href=&quot;&lt;?php echo str_replace(('?'.$_SERVER['QUERY_STRING']), '', $_SERVER['REQUEST_URI']); ?&gt;&quot;&gt;Date&lt;/a&gt;
 | &lt;a href=&quot;&lt;?php echo str_replace(('?'.$_SERVER['QUERY_STRING']), '', $_SERVER['REQUEST_URI']).'/?sort=title'; ?&gt;&quot;&gt;Title&lt;/a&gt;
 &lt;/p&gt;
</pre>
<p><strong>This will display like this:</strong> Sort by: <a href="#">Date</a> | <a href="#">Title</a></p>
<p>Then use this code above <strong>the Loop</strong>:</p>
<div>
<pre class="brush: php; light: true; title: ;">&lt;?php if($_GET['sort'] == 'title') query_posts('orderby=title&amp;order=ASC'); ?&gt;</pre>
<p>This will sort <strong>Posts</strong> by date as default, but sort by title if the user clicks <strong>sort by title</strong>.</p>
<p><img class="alignleft size-full wp-image-181" title="Info" src="http://wpwizard.net/wp-content/uploads/2009/12/Info_icon.png" alt="Info" width="48" height="48" />If you only want this function in one <strong>Category</strong>, you duplicate <code>category.php</code> and name it <code>category-X.php</code>, where X is the ID of the <strong>Category</strong>. (From version 2.9 of WordPress you can name it <code>category-{category-slug}.php</code>.)</p>
</div>
<div class="shr-publisher-165"></div>]]></content:encoded>
			<wfw:commentRss>http://wpwizard.net/wordpress-hacks/sort-posts-by-date-or-title/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Display different number of Posts</title>
		<link>http://wpwizard.net/wordpress-hacks/display-different-number-of-posts/</link>
		<comments>http://wpwizard.net/wordpress-hacks/display-different-number-of-posts/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 11:35:11 +0000</pubDate>
		<dc:creator>Stian Andreassen</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[the Loop]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.stianandreassen.com/?p=140</guid>
		<description><![CDATA[A single line of code is all that's needed to change the number of displayed Posts in different contexts.]]></description>
			<content:encoded><![CDATA[<p>When using WordPress, I often see the need to display a different number of <strong>Posts </strong>in different contexts. Maybe I just want to display the five newest on the frontpage, but show 50 (with just the headlines) when browsing <strong>Archives</strong>, etc. WordPress doesn&#8217;t let you do this &#8211; at least not from the Dashboard &#8211; in <strong>Reader Settings</strong> there&#8217;s only one field that lets you set the number of <strong>Posts</strong>, which is used all-over (defaults to 10).</p>
<p><span id="more-140"></span></p>
<p>But there are ways around this. The plugin <a href="http://moshublog.com/2007/10/30/custom-query-string-reloaded-for-wordpress-23-with-tag-support/">Custom Query String Reloaded</a> lets you set a different numbers of <strong>Posts </strong>for everthing from the frontpage, to archives and categories.</p>
<p>You don&#8217;t need to use a plugin, however, if you know your way around your <strong>Theme</strong>-files. To change the number of displayed <strong>Posts</strong>, you simply need this little code snippet:</p>
<pre class="brush: php; light: true; title: ;">&lt;?php query_posts('posts_per_page=5'); ?&gt;</pre>
<p>Insert it above <strong>the Loop</strong> in your template-files, and change the number to the number of <strong>Posts </strong>you want to display. Remember to use <a href="http://codex.wordpress.org/Conditional_Tags">Conditional Tags</a> if you want different results on different pages. For example, if you want to show five <strong>Posts </strong>on the frontpage only, you add this code above<strong> the Loop</strong> in your <code>index.php</code>:</p>
<pre class="brush: php; light: true; title: ;">&lt;?php if(is_home()) query_posts('posts_per_page=5'); ?&gt;</pre>
<p><strong>The Loop</strong> (usually) starts with the line <code>&lt;?php if (have_posts()) : ?&gt;</code>, so insert your code above this.</p>
<p>This can be used in practically every template-file that deals with multiple <strong>Posts</strong>; <code>index.php</code>, <code>archives.php</code>, <code>category.php</code>, and so forth.</p>
<div class="shr-publisher-140"></div>]]></content:encoded>
			<wfw:commentRss>http://wpwizard.net/wordpress-hacks/display-different-number-of-posts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

