<?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; template</title>
	<atom:link href="http://wpwizard.net/tag/template/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>Setting up a multilingual WordPress site</title>
		<link>http://wpwizard.net/customizing-wordpress/setting-up-a-multilingual-wordpress-site/</link>
		<comments>http://wpwizard.net/customizing-wordpress/setting-up-a-multilingual-wordpress-site/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:25:40 +0000</pubDate>
		<dc:creator>Stian Andreassen</dc:creator>
				<category><![CDATA[Customizing WordPress]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stianandreassen.com/?p=316</guid>
		<description><![CDATA[With just a simple Template and script in place of wp_list_pages(), you can make multilingual WordPress sites.]]></description>
			<content:encoded><![CDATA[<p>I often have clients who need a <strong>multilingual website</strong>. This isn&#8217;t plug &amp; play when it comes to WordPress (though rumor has it WP 3.0 will support multiple sites in one install, which probably will make multilingual WP sites a breeze), but there are sollutions. WordPress’s <strong>Page</strong> system is pretty flexible, and can with just a few moderations be used for multiple languages.</p>
<h3><span id="more-316"></span>How-To:</h3>
<p>First off I add the <a href="http://www.wprecipes.com/wordpress-page-template-to-redirect-to-first-child-page">Redirect To First Child Template</a> to the <strong>Theme</strong>. What this does, is look for the first <strong>Child</strong> of a <strong>Page</strong>, and redirect to it. (To controll which Child is the first, I use the plugin <a href="http://wordpress.org/extend/plugins/my-page-order/">My Page Order</a>.) I then create a Page for each of the languages I want, employing the <strong>Redirect-Template</strong> on them. I then add what is to be the main menu items for each language, and add them as Children of their respective language Page. If the site has any subnavigation, I simply add these as Children to the Child-of-language-Pages. Follow me?</p>
<p>This gives me a rough navigation along the lines of:</p>
<ul>
<li>ENGLISH
<ul>
<li>Main Page</li>
<li>Products</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</li>
<li>GERMAN
<ul>
<li>Startseite</li>
<li>Produkte</li>
<li>Wir über uns</li>
<li>Kontakt</li>
</ul>
</li>
<li>FRENCH
<ul>
<li>Page principale</li>
<li>Produits</li>
<li>A propos de nous</li>
<li>Contact</li>
</ul>
</li>
</ul>
<p>(Apologies for poor translation, if any, had to use Google Translator.)</p>
<p>Then I add the code for the navigation to the <strong>Theme</strong>. We can&#8217;t simply use <code>wp_list_pages()</code> for this, as it will simply output a list like the one above. Instead we use this script where we want our navigation to appear:</p>
<pre class="brush: php; highlight: [40]; title: ;">
&lt;?php
// CHECK IF WE ARE ON A PAGE
 if(is_page()) {
 $currenttitle = $post-&gt;post_title.'&lt;/a&gt;';
 $subpages = wp_list_pages('title_li=&amp;echo=0&amp;sort_column=menu_order&amp;depth=1&amp;child_of='.$post-&gt;ID);

 $id = $post-&gt;post_parent;
 $sidebar_title = get_page($id);
 if($sidebar_title) {
 $prevpageparent = $sidebar_title-&gt;post_parent;
 }
 rewind_posts();

 if($subpages) {
 $pages=wp_list_pages(&quot;title_li=&amp;echo=1&amp;sort_column=menu_order&amp;depth=1&amp;echo=0&amp;child_of=&quot;.$post-&gt;post_parent);
 $pagelisting = str_replace($currenttitle, $currenttitle.'&lt;div id=&quot;submenu&quot;&gt;&lt;ul&gt;'.$subpages.'&lt;/ul&gt;&lt;/div&gt;', $pages);
 echo $pagelisting;
 }

 elseif($post-&gt;post_parent &amp;&amp; $prevpageparent&gt;'0') {
 $parent = $post-&gt;post_parent;

 $id = $post-&gt;post_parent;
 $myquery = new WP_Query(&quot;page_id=$id&quot;);
 $currenttitle = $myquery-&gt;post-&gt;post_title.'&lt;/a&gt;';

 $subpages = wp_list_pages('title_li=&amp;echo=0&amp;sort_column=menu_order&amp;depth=1&amp;echo=0&amp;child_of='.$post-&gt;post_parent);

 $pages = wp_list_pages(&quot;title_li=&amp;echo=1&amp;sort_column=menu_order&amp;depth=1&amp;echo=0&amp;child_of=&quot;.$prevpageparent);
 $pagelisting = str_replace($currenttitle, $currenttitle.'&lt;div id=&quot;submenu&quot;&gt;&lt;ul&gt;'.$subpages.'&lt;/ul&gt;&lt;/div&gt;', $pages);
 echo $pagelisting;
 }

 else { wp_list_pages(&quot;title_li=&amp;echo=1&amp;sort_column=menu_order&amp;depth=1&amp;child_of=&quot;.$post-&gt;post_parent);
 }
 rewind_posts();
} else {
// WE ARE NOT ON A PAGE, BUT A POST, CATEGORY VIEW, ETC
// SO WE HAVE TO DEFINE THE DEFAULT LANGUAGE MANUALLY AT THE END OF THE STRING
 wp_list_pages(&quot;title_li=&amp;echo=1&amp;sort_column=menu_order&amp;depth=1&amp;child_of=1&quot;);
} ?&gt;
</pre>
<p><strong>Line 40 is important</strong>; if we&#8217;re <em>not</em> on a <strong>Page</strong> the script can&#8217;t traverse back to it&#8217;s source (the Page that defines the language), so we have to manually put in the ID for the language Page we want to use as default, f.i. ENGLISH, at the end of <code>child_of=</code>.</p>
<p><strong>Also note</strong> that this script is custom made to show vertical navigation, with any subnavigation positioned directly below its Parent both <em>when the Parent is active</em> and <em>when the Child is active</em>, like this:</p>
<ul>
<li>Main Page</li>
<li><strong>Products</strong>
<ul>
<li>Software</li>
<li><em>Hardware</em></li>
<li>Upgrades</li>
</ul>
</li>
<li>About us</li>
<li>Contact</li>
</ul>
<p>It can be shortened and/or modified for other needs and types of navigation.</p>
<h3>A few notes:</h3>
<ul>
<li>It&#8217;s easiest to add the links for each language into the <strong>Theme</strong> manually. If you want to use flag icons, or simply text links, you can simply add: <code>&lt;a href="&lt;?php echo get_bloginfo('home').'/english/'; ?&gt;"&gt;English&lt;/a&gt;</code> and so forth.</li>
<li>If you want the <em>ENGLISH &gt; Main Page</em> to be the default Front Page, simply go to <strong>Settings &gt; Reading</strong> in <strong>WP-admin</strong> and set Static Page: ENGLISH to display as Front Page.</li>
<li><strong>And most important:</strong> This won&#8217;t take you from the English <strong>Product</strong> Page to the French <strong>Produits</strong> Page by clicking the flag. When you change language, you will be redirected to the Front Page of the selected language!</li>
</ul>
<div class="shr-publisher-316"></div>]]></content:encoded>
			<wfw:commentRss>http://wpwizard.net/customizing-wordpress/setting-up-a-multilingual-wordpress-site/feed/</wfw:commentRss>
		<slash:comments>0</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>

