<?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>Weborithm &#187; Tutorials</title>
	<atom:link href="http://www.weborithm.com/topic/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weborithm.com</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 07:45:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Showing Relevant Next/Previous Blog Posts</title>
		<link>http://www.weborithm.com/showing-relevant-nextprevious-blog-posts/</link>
		<comments>http://www.weborithm.com/showing-relevant-nextprevious-blog-posts/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 15:55:12 +0000</pubDate>
		<dc:creator>Hyder</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress Navigation]]></category>

		<guid isPermaLink="false">http://www.weborithm.com/?p=330</guid>
		<description><![CDATA[Sometimes when you build a WordPress theme you may want you to only show relevant Next and Previous post links. For instance, if you created a specific category for your &#8220;Galleries&#8221; and only used the &#8220;Gallery&#8221; Post format in that category you might want to ONLY show other Galleries in the post navigation. Here&#8217;s how... <p class="excerpt_more"><a href="http://www.weborithm.com/showing-relevant-nextprevious-blog-posts/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Sometimes when you build a WordPress theme you may want you to only show relevant <em>Next</em> and <em>Previous</em> post links. For instance, if you created a specific category for your &#8220;Galleries&#8221; and only used the &#8220;Gallery&#8221; Post format in that category you might want to ONLY show other Galleries in the post navigation. Here&#8217;s how you do that.</p>
<p>First off, here&#8217;s the HTML for the navigation:</p>
<pre class="brush: xml; title: ; notranslate">&lt;div class=&quot;navigation&quot;&gt;
&lt;div class=&quot;alignleft&quot;&gt;&lt;!-- Previous Post Link --&gt;&lt;/div&gt;
&lt;div class=&quot;alignright&quot;&gt;&lt;!-- Next Post Link --&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
<p>The code we&#8217;ll need to show the Next and Previous post links is:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php previous_post_link(''); ?&gt;
&lt;?php next_post_link(''); ?&gt;</pre>
<p>Now, let&#8217;s customize the PHP to show our relevant Posts from that specific category <strong>only</strong>.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php previous_post_link('%link', 'Previous post', TRUE); ?&gt;
&lt;?php next_post_link('%link', 'Next post', TRUE); ?&gt;</pre>
<p>Here&#8217;s an explanation of the above code.</p>
<ol>
<li><strong>%link</strong> &#8211; This will show the link for the previously or recently published Post from the one being viewed.</li>
<li><strong>Previous post/Next post</strong> &#8211; This will be the anchor text for the respective links.</li>
<li><strong>TRUE</strong> &#8211; This will tell the code to only use the same category as the Post being viewed to show the relevant links.</li>
</ol>
<p>Here&#8217;s the final code:</p>
<pre class="brush: php; title: ; notranslate">&lt;div class=&quot;navigation&quot;&gt;
&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_post_link('%link', 'Previous post', TRUE); ?&gt;&lt;/div&gt;
&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_post_link('%link', 'Next post', TRUE); ?&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
<p>You can use the CSS classes to format the output however you like. You can see an example of this type of navigation at the very bottom of this post.</p>
<p>If you found this tutorial helpful please consider tweeting or liking it! Do add your comment below on how you&#8217;ve used it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weborithm.com/showing-relevant-nextprevious-blog-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Page Template to Show Custom Post Type Loops</title>
		<link>http://www.weborithm.com/page-template-to-show-custom-post-type-loops/</link>
		<comments>http://www.weborithm.com/page-template-to-show-custom-post-type-loops/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 12:32:03 +0000</pubDate>
		<dc:creator>Hyder</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Custom Post Types]]></category>
		<category><![CDATA[Page Templates]]></category>

		<guid isPermaLink="false">http://www.weborithm.com/?p=322</guid>
		<description><![CDATA[If you&#8217;re using Custom Post Types you&#8217;re obviously amazed by the amount of options such a feature can provide you in WordPress. I recently updated my Craft WordPress theme which implements Custom Post Types for &#8220;Portfolios&#8221;. The format allows the user to set up easy project posts and show them in a different styling from... <p class="excerpt_more"><a href="http://www.weborithm.com/page-template-to-show-custom-post-type-loops/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using Custom Post Types you&#8217;re obviously amazed by the amount of options such a feature can provide you in WordPress. I recently updated my <a title="Preview the theme here" href="http://bit.ly/craftwp">Craft WordPress theme</a> which implements Custom Post Types for &#8220;Portfolios&#8221;. The format allows the user to set up easy <em>project posts</em> and show them in a different styling from their <em>regular posts</em>.</p>
<p>Here&#8217;s a walk-through of how I developed my <strong>Page Template to show posts from a Custom Post Type</strong>.</p>
<p>1. First we set up the header to query the Custom Post Type. This tells the Page Template to query the relevant type, in this case the &#8220;Portfolio&#8221; post type.</p>
<p>Here&#8217;s the code for that:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php get_header(); query_posts('post_type=portfolio&amp;showposts=-1') ?&gt;</pre>
<p>2. Then we set up the HTML to show the posts from the Portfolio post type. Here&#8217;s what my HTML looks like:</p>
<pre class="brush: php; title: ; notranslate">&lt;div class=&quot;portfolio-container&quot;&gt;

&lt;h1&gt;Page Template Title&lt;/h1&gt;
&lt;div id=&quot;portfolio-container&quot;&gt;
&lt;ul id=&quot;portfolio-filter&quot;&gt;
&lt;li&gt;&lt;a href=&quot;#&quot;&gt;All&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;!-- Portfolio Taxonomy/Category Loop Comes Here --&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ul id=&quot;portfolio&quot;&gt;
&lt;!-- Start Post Loop --&gt;
&lt;li&gt;&lt;!-- Post Thumbnail Comes Here --&gt;
&lt;h3&gt;&lt;a href=&quot;Post Link Comes Here&quot;&gt;Post Title Comes Here&lt;/a&gt;&lt;/h3&gt;
&lt;/li&gt;
&lt;!-- Finish Post Loop --&gt;
&lt;/ul&gt;

&lt;/div&gt;&lt;!-- Portfolio Container --&gt;

&lt;/div&gt;&lt;!-- Post Class --&gt;</pre>
<p><strong>Now let&#8217;s add in all the fun stuff!</strong></p>
<p>3. First we set up the main container with the default WordPress generated post class tag and add in the Title tag as well:</p>
<pre class="brush: php; title: ; notranslate">&lt;div &lt;?php post_class('portfolio-page taxonomy-portfolio') ?&gt;&gt;
&lt;h1&gt;&lt;?php the_title(); ?&gt; &lt;?php edit_post_link('Edit', ' | ', ''); ?&gt;&lt;/h1&gt;</pre>
<p>4. Next, since we&#8217;re using a sortable technique here to filter the Portfolio projects themselves (that&#8217;s another tutorial for another day) I&#8217;m going to leave the &#8220;All&#8221; as a placeholder for showing all the taxonomies and the rest will display by using the <em>foreach</em> command. Explanation for each line is commented in the code:</p>
<pre class="brush: php; title: ; notranslate">&lt;ul id=&quot;portfolio-filter&quot;&gt;

&lt;li&gt;&lt;a href=&quot;#&quot;&gt;All&lt;/a&gt;&lt;/li&gt;

&lt;?php
// Create an array and assign the projects taxonomy to it
$args = array( 'taxonomy' =&gt; 'projects' );
// Call the categories from this array
$categories=get_categories($args);
// Now, loop through them and...
foreach ($categories as $category) {
//...display each categories name
echo '&lt;li&gt;&lt;a href=&quot;#&quot;&gt;'.$category-&gt;name;
echo '&lt;/a&gt;&lt;/li&gt;';
// Fin.
} ?&gt;

&lt;/ul&gt;</pre>
<p>5. Now, that our taxonomies are displaying up above, let&#8217;s display the actual <em>content</em> from this Custom Post Type. Since it&#8217;s a Page Template, I want to just show the &#8220;featured image&#8221; and the title of the Post. The code for that looks like this:</p>
<pre class="brush: php; title: ; notranslate">&lt;ul id=&quot;portfolio&quot;&gt;

&lt;!-- Start the loop --&gt;
&lt;?php if (have_posts()) : ?&gt;
&lt;?php while (have_posts()) : the_post(); ?&gt;

&lt;li&gt;
&lt;!-- Since I want to show the featured image, check if it's available --&gt;
&lt;?php if (has_post_thumbnail() ) { ?&gt;
&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;nofollow&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_post_thumbnail('portfolio-image', array( 'title' =&gt; ''.get_the_title().'' ) ); ?&gt;&lt;/a&gt;
&lt;?php } ?&gt;
&lt;!-- Next we show the title of the Post --&gt;
&lt;h3&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php echo ShortenText(get_the_title()); ?&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/li&gt;
&lt;!-- End the Loop --&gt;
&lt;?php endwhile; endif; // End Portfolio ?&gt;
&lt;/ul&gt;

&lt;!-- Adding the closing div and get_footer to close out the template --&gt;
&lt;/div&gt;&lt;!-- Portfolio Container --&gt;
&lt;/div&gt;

&lt;?php get_footer(); ?&gt;</pre>
<p>Almost done&#8230;</p>
<p>6. You might want to add this to your <em>functions.php</em> if you want to use the above code in your Page Template:</p>
<pre class="brush: php; title: ; notranslate">add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'portfolio',
array(
'labels' =&gt; array(
'name' =&gt; __( 'Portfolio' ),
'singular_name' =&gt; __( 'Portfolio' ),
'add_new' =&gt; _x('Add New Project', 'portfolio item'),
'add_new_item' =&gt; __('New Portfolio Project'),
'edit_item' =&gt; __('Edit Portfolio Project'),
'new_item' =&gt; __('New Portfolio Project'),
'view_item' =&gt; __('View Portfolio Project'),
'search_items' =&gt; __('Search Your Portfolio'),
'not_found' =&gt;  __('Nothing found'),
'not_found_in_trash' =&gt; __('Nothing found in Trash'),
),
'public' =&gt; true,
'has_archive' =&gt; true,
'publicly_queryable' =&gt; true,
'show_ui' =&gt; true,
'query_var' =&gt; true,
'rewrite' =&gt; array('slug' =&gt; 'portfolio'),
'capability_type' =&gt; 'post',
'supports' =&gt; array('title','editor','thumbnail','comments','excerpt'),
'taxonomies' =&gt; array( 'category ')
)
);
}

register_taxonomy(&quot;projects&quot;, array(&quot;portfolio&quot;), array(&quot;hierarchical&quot; =&gt; true, &quot;label&quot; =&gt; &quot;Project Category&quot;, &quot;singular_label&quot; =&gt; &quot;Category: &quot;, &quot;rewrite&quot; =&gt; true));</pre>
<p><em>Could you just give me the final code already?! (the filterable action needs some additional jQuery and magic, which will probably be shown in another tutorial)</em></p>
<p>Here&#8217;s the final Page Template code<em>:<br />
</em></p>
<pre class="brush: php; title: ; notranslate">&lt;?php
/**
* @package WordPress
* @subpackage Your Theme Name
*/
/*
Template Name: Portfolio
*/
?&gt;

&lt;?php get_header(); query_posts('post_type=portfolio&amp;showposts=-1') ?&gt;

&lt;div &lt;?php post_class('portfolio-page taxonomy-portfolio') ?&gt;&gt;

&lt;h1&gt;&lt;?php the_title(); ?&gt; &lt;?php edit_post_link('Edit', ' | ', ''); ?&gt;&lt;/h1&gt;
&lt;div id=&quot;portfolio-container&quot;&gt;

&lt;ul id=&quot;portfolio-filter&quot;&gt;
&lt;li&gt;&lt;a href=&quot;#&quot;&gt;All&lt;/a&gt;&lt;/li&gt;
&lt;?php
$args = array( 'taxonomy' =&gt; 'projects' );
$categories=get_categories($args);
foreach ($categories as $category) {
echo '&lt;li&gt;&lt;a href=&quot;#&quot;&gt;'.$category-&gt;name;
echo '&lt;/a&gt;&lt;/li&gt;';
} ?&gt;
&lt;/ul&gt;

&lt;ul id=&quot;portfolio&quot;&gt;
&lt;?php if (have_posts()) : ?&gt;
&lt;?php while (have_posts()) : the_post(); ?&gt;
&lt;li&gt;&lt;?php if (has_post_thumbnail() ) { ?&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;nofollow&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_post_thumbnail('portfolio-image', array( 'title' =&gt; ''.get_the_title().'' ) ); ?&gt;&lt;/a&gt;&lt;?php } ?&gt;&lt;h3&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php echo ShortenText(get_the_title()); ?&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/li&gt;
&lt;?php endwhile; endif; // End Portfolio ?&gt;
&lt;/ul&gt;

&lt;/div&gt;&lt;!-- Portfolio Container --&gt;

&lt;/div&gt;

&lt;?php get_footer(); ?&gt;</pre>
<p>Here&#8217;s a working example of the template in my <a title="Have a look" href="http://test.weborithm.com/craft/my-portfolio/">Craft WordPress theme</a>.</p>
<p>If you found this tutorial helpful please leave a comment and let me know how you&#8217;ve used it. A tweet <em>or</em> like would be just as awesome, thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weborithm.com/page-template-to-show-custom-post-type-loops/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

