<?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>Kriesi.at - Wordpress Themes and HTML Templates &#187; Wordpress Tutorial</title>
	<atom:link href="http://www.kriesi.at/archives/category/wordpress-tutorial/feed" rel="self" type="application/rss+xml" />
	<link>http://www.kriesi.at</link>
	<description>Premium Theme Design</description>
	<lastBuildDate>Mon, 06 Feb 2012 16:31:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>15 useful WordPress Functions you probably don&#8217;t know</title>
		<link>http://www.kriesi.at/archives/15-useful-wordpress-functions-you-probably-dont-know</link>
		<comments>http://www.kriesi.at/archives/15-useful-wordpress-functions-you-probably-dont-know#comments</comments>
		<pubDate>Mon, 11 Oct 2010 17:20:57 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=1154</guid>
		<description><![CDATA[While I was building my first premium Wordpress Plugin - <a href="http://aviathemes.com/plugins/avia-feedback-box/">the Avia Feedback Box</a> - I needed to solve quite a few problems I have never encounterd when creating themes. During my research I stumbled upon several really cool wordpress functions that I want to share with you.]]></description>
			<content:encoded><![CDATA[<p>While I was building my first premium WordPress Plugin &#8211; <a href="http://aviathemes.com/plugins/avia-feedback-box/">the Avia Feedback Box</a> &#8211; I needed to solve quite a few problems I have never encounterd when creating themes. During my research I stumbled upon several really cool wordpress functions that I want to share with you.<br />
<span id="more-1154"></span></p>
<h4>WordPress Transient API</h4>
<pre>set_transient(), get_transient(), delete_transient()</pre>
<p>This is a function set very similar to get_options() and update_options() which helps to easily store and retrieve data in your options database table. The big difference here is that you also pass a time parameter which acts as expiration date for the database entry.</p>
<p>Once the time has expired the data is removed. This is especially useful if you want to cache data or query results for a short amount of time. An example would be a twitter widget which retrieves data from the twitter api, but since twitter is down pretty often it would be wise to save that data for a few minutes. That also would speed up the site for subsqequent page requests since you don&#8217;t need to connect to an external API.</p>
<p>It works pretty easy: the function set_transient accepts 3 parameters:</p>
<pre>set_transient($transient, $value, $expiration);</pre>
<p>so saving a value to your database for an hour would look like this:</p>
<pre>set_transient('the_name', $special_query_results, 60*60);</pre>
<p>getting the value like this:</p>
<pre>$value = get_transient('the_name');</pre>
<p><a href="http://codex.wordpress.org/Transients_API">http://codex.wordpress.org/Transients_API</a></p>
<h4>WordPress &#8220;Cron Jobs&#8221;</h4>
<pre>wp_schedule_event(time(), 'hourly', 'my_schedule_hook');</pre>
<p>Schedules a hook which will be executed by the WordPress actions core on  a specific interval, specified by you. The action will trigger when  someone visits your WordPress site, if the scheduled time has passed.</p>
<p>So if you want to execute some code on a regular base, like checking an RSS Feed, doing a database backup or reseting database values this function will do it for you. Unfortunatley its not as easy to use as transient but here is a short article on how it is done:<br />
<a href="http://themocracy.com/2010/02/wp-cron-automating-scheduling/"> http://themocracy.com/2010/02/wp-cron-automating-scheduling/</a><br />
<a href="http://codex.wordpress.org/Function_Reference/wp_schedule_event">http://codex.wordpress.org/Function_Reference/wp_schedule_event</a></p>
<h4>WordPress HTTP API</h4>
<pre>wp_remote_get( $url, $args = array() );</pre>
<p>An easy to use function if you want to retrieve the content of a Webpage. The function stores the result within an easily accessible array. Not only do you get the result content of the webpage, you also get header informations and response codes. This function is also capable of retrieving feed content which also makes it useful if you want to create a twitter plugin or an rss reader with wordpress.</p>
<p><a href="http://codex.wordpress.org/HTTP_API">http://codex.wordpress.org/HTTP_API</a><br />
<a href="http://codex.wordpress.org/Function_API/wp_remote_get">http://codex.wordpress.org/Function_API/wp_remote_get</a></p>
<h4>Easily Fetch an RSS Feed with WordPress</h4>
<pre>$feed = fetch_feed( $uri );</pre>
<p>fetch_feed is another simple wordpress method to get feed content. It also has the added benefit that it uses the <a title="http://simplepie.org/" href="http://simplepie.org/">SimplePie</a> and FeedCache functionality for retrieval and parsing and automatic caching.</p>
<p><a href="http://codex.wordpress.org/Function_Reference/fetch_feed">http://codex.wordpress.org/Function_Reference/fetch_feed</a></p>
<h4>WordPress mail function</h4>
<pre>wp_mail()
wp_mail( $to, $subject, $message, $headers, $attachments );</pre>
<pre>Example:

$to = 'kriesi@gmail.com';
$subject = 'Hello Kriesi!';
$message = 'This message was sent by wordpress'

$mail = wp_mail($to, $subject, $message);

if($mail) echo 'Mail delivered';</pre>
<p>An incredible useful and exceptional easy to use function that also allows you to send headers and attachments, allows plain text sending and html messages and quite a few other options!</p>
<p><a href="http://codex.wordpress.org/Function_Reference/wp_mail">http://codex.wordpress.org/Function_Reference/wp_mail</a></p>
<h4>WordPress Human Time</h4>
<pre>human_time_diff( $from, $to )</pre>
<p>A feature to mimic twitter like time display. Instead of outputting the time in a basic format you can display it like this:</p>
<p><small>Kriesi posted 13 hours ago</small></p>
<p><a href="http://codex.wordpress.org/Function_Reference/human_time_diff">http://codex.wordpress.org/Function_Reference/human_time_diff</a></p>
<h4>WordPress get comments</h4>
<pre>get_comments()</pre>
<p>Sometimes its neccessary to retrieve the comments outside of the comments loop like I did with the <a href="http://aviathemes.com/plugins/avia-feedback-box/">Avia Feedback Box </a>Plugin, where comments are displayed via ajax. This function helps you in doing so <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://codex.wordpress.org/Function_Reference/get_comments">http://codex.wordpress.org/Function_Reference/get_comments</a></p>
<h4>WordPress validation of strings</h4>
<pre>wp_kses($string, $allowed_html, $allowed_protocols);</pre>
<p>wp_kses is a very usefull function when it comes to sanitizing untrusted user input. This function makes sure that only the allowed HTML element names,  attribute names and attribute values plus only sane HTML entities will  occur in $string.</p>
<p><a href="http://codex.wordpress.org/Function_Reference/wp_kses">http://codex.wordpress.org/Function_Reference/wp_kses</a></p>
<h4>WordPress text transformation</h4>
<pre>wptexturize()</pre>
<p>A text transformation function that converts commonly used strings into the typographical correct signs. Used for dashes, ellipsis etc and will also add typograpic quotes to certain phrases.</p>
<p><a href="http://codex.wordpress.org/Function_Reference/wptexturize">http://codex.wordpress.org/Function_Reference/wptexturize</a></p>
<pre>wpautop()</pre>
<p>The last text transformation tool on the list is used by wordpress to ad &lt;p&gt; tags to a string by replacing double &lt;br/&gt; tags</p>
<p><a href="http://codex.wordpress.org/Function_Reference/wpautop">http://codex.wordpress.org/Function_Reference/wpautop</a></p>
<h4>WordPress Shortcode API</h4>
<pre>add_shortcode(), do_shortcode()</pre>
<p>add_shortcode() is an easy way to create macros for your post content. for example lets say you want to wrap some content inside the post area within a div with some additional classes and ids that allows you to create multiple columns. you could of course just switch to the html editor and enter</p>
<pre>&lt;div class='one_third'&gt;Content goes here&lt;/div&gt;</pre>
<p>Easier and more convenient especially if you are dealing with customers who dont know html would be a shortcode solution within your functions.php file:</p>
<pre>function column_shortcode( $atts, $content = null ) {
   return '&lt;div class='one_third&gt;' . $content . '&lt;/div&gt;';
}

add_shortcode('one_third_column', 'column_shortcode');</pre>
<p>You could then use this shortcode in your post content:</p>
<pre>[one_third_column]Content goes here[/one_third_column]</pre>
<p>If you would like to nest shortcodes within each other you would need to make sure to add the do_shortcode method to your function like this:</p>
<pre>column_shortcode( $atts, $content = null ) {
   return '&lt;div class='one_third&gt;' . do_shortcode($content) . '&lt;/div&gt;';
}</pre>
<p><a href="http://codex.wordpress.org/Shortcode_API">http://codex.wordpress.org/Shortcode_API</a></p>
<h4>Create WordPress post with a php function:</h4>
<pre>wp_insert_post()</pre>
<p>This function inserts posts pages and custom post types in the database. It sanitizes  variables, does some checks, fills in missing variables like date/time,  etc. very handy when you need to create and insert posts by user input. This function fits perfectly if you have a front end form for example and users can suggest posts.</p>
<p><a href="http://codex.wordpress.org/Function_Reference/wp_insert_post">http://codex.wordpress.org/Function_Reference/wp_insert_post</a></p>
<h4>Create WordPress comment with a php function:</h4>
<pre>wp_insert_comment()</pre>
<p>Similar to wp_insert_posts this function inserts a comment. Might also come in handy <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://codex.wordpress.org/Function_Reference/wp_insert_comment">http://codex.wordpress.org/Function_Reference/wp_insert_comment</a></p>
<h4>WordPress Object Cache:</h4>
<pre>wp_cache_add(),  wp_cache_set(),  wp_cache_get(),  wp_cache_delete, wp_cache_replace(), wp_cache_flush</pre>
<p><tt>WP_Object_Cache</tt> is WordPress&#8217; class for caching data which may  be computationally expensive to regenerate, such as the result of  complex database queries. If you care for theme and plugin performance you should definitley read the wordpress codex entry for this topic!</p>
<p><a href="http://codex.wordpress.org/Function_Reference/WP_Cache">http://codex.wordpress.org/Function_Reference/WP_Cache</a></p>
<h4>Kill wordpress execution:</h4>
<pre>wp_die()</pre>
<p>An appropriate end for this post: the wp_die function</p>
<p>wp_die kills the WordPress execution and display <a title="wikipedia:HTML" href="http://en.wikipedia.org/wiki/HTML">HTML</a> message with error message.</p>
<p>A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the  user. It is recommended to use this function only when the execution  should not continue any further.</p>
<p><a href="http://codex.wordpress.org/Function_Reference/wp_die">http://codex.wordpress.org/Function_Reference/wp_die</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/15-useful-wordpress-functions-you-probably-dont-know/feed</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
		<item>
		<title>How to build a WordPress Post Pagination without plugin</title>
		<link>http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin</link>
		<comments>http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin#comments</comments>
		<pubDate>Tue, 21 Sep 2010 16:41:26 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=1122</guid>
		<description><![CDATA[Since I got asked a few times now which function I am using to display the pagination within my themes I thought it was about time to share it with everyone who doesn't want to use a plugin for a wordpress post pagination ;)]]></description>
			<content:encoded><![CDATA[<p>WordPress only comes bundled with the &#8220;next page&#8221; and &#8220;previous page&#8221; links to navigate between different blog overview pages. If you happen to have a blog with a lot of posts or simply want to offer a better user experience I would recommend to remove those links and replace them with a pagination like most people (including me) are using in their templates.<span id="more-1122"></span></p>
<p><a href="http://www.kriesi.at/themes/habitat/">Habitat</a> for example (my latest blog theme) uses it. Just scroll down the front page and you will see those little paginated buttons.</p>
<p><strong>Why should you use them? </strong><br />
Because they are easier to navigate and the user instantly knows how many posts and pages are available. Its simply good user experience <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Using a plugin for this task may be an overkill since you really only need to add a few lines of php and css to your theme which I will show you now:</p>
<h3>The function</h3>
<p>If you just want to copy/paste the function into your theme feel free to do so, a more detailed description can be found bellow:</p>
<pre>function kriesi_pagination($pages = '', $range = 2)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query-&gt;max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "&lt;div class='pagination'&gt;";
         if($paged &gt; 2 &amp;&amp; $paged &gt; $range+1 &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link(1)."'&gt;&amp;laquo;&lt;/a&gt;";
         if($paged &gt; 1 &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link($paged - 1)."'&gt;&amp;lsaquo;&lt;/a&gt;";

         for ($i=1; $i &lt;= $pages; $i++)
         {
             if (1 != $pages &amp;&amp;( !($i &gt;= $paged+$range+1 || $i &lt;= $paged-$range-1) || $pages &lt;= $showitems ))
             {
                 echo ($paged == $i)? "&lt;span class='current'&gt;".$i."&lt;/span&gt;":"&lt;a href='".get_pagenum_link($i)."' class='inactive' &gt;".$i."&lt;/a&gt;";
             }
         }

         if ($paged &lt; $pages &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link($paged + 1)."'&gt;&amp;rsaquo;&lt;/a&gt;";  
         if ($paged &lt; $pages-1 &amp;&amp;  $paged+$range-1 &lt; $pages &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link($pages)."'&gt;&amp;raquo;&lt;/a&gt;";
         echo "&lt;/div&gt;\n";
     }
}</pre>
<h3>How to use  &amp; Step by Step description</h3>
<p>Displaying the pagination links on a default index page is rather easy. Call</p>
<pre>kriesi_pagination();</pre>
<p>and you are done.</p>
<p>As you can see we got 2 optional parameters to pass:</p>
<pre>function kriesi_pagination($pages = '', $range = 2)</pre>
<p>The first one is the number of pages: passing this is only necessary if you are using a custom loop, something I will explain a little bit later.</p>
<p>The second parameter sets the number of links to display. Range tells the script how many links before and after the current page should be displayed before it only shows the small arrows. For example with the default range of 2, if you are currently visiting the first page the script would display the 2 following pages, the next page button and the last page button:</p>
<div class="pagination"><span class="current">1</span><a class="inactive" href="http://www.kriesi.at/blog/page/2">2</a><a class="inactive" href="http://www.kriesi.at/blog/page/3">3</a><a href="http://www.kriesi.at/blog/page/2">›</a><a href="http://www.kriesi.at/blog/page/12">»</a></div>
<p>if we would visit page number 4 the script would show page 4 as the current page, would directly link to page 2 and 3 as well to 5 and 6. All other would be hidden:</p>
<div class="pagination"><a href="http://www.kriesi.at/blog/">«</a><a href="http://www.kriesi.at/blog/page/3">‹</a><a class="inactive" href="http://www.kriesi.at/blog/page/2">2</a><a class="inactive" href="http://www.kriesi.at/blog/page/3">3</a><span class="current">4</span><a class="inactive" href="http://www.kriesi.at/blog/page/5">5</a><a class="inactive" href="http://www.kriesi.at/blog/page/6">6</a><a href="http://www.kriesi.at/blog/page/5">›</a><a href="http://www.kriesi.at/blog/page/12">»</a></div>
<p>For easier arithmetic operations afterwards we also store the max number of items to display in a separate variable:</p>
<pre>$showitems = ($range * 2)+1;</pre>
<p>Next we need access to the global variable <strong>$paged</strong>. WordPress uses this variable to store which page we are currently viewing. If that variable is empty we set it to 1. Why do we need to know it? The page we are currently at should not be linked, it should be displayed as &#8220;active&#8221;.</p>
<pre>global $paged;
if(empty($paged)) $paged = 1;</pre>
<p>Now we know which page we are currently viewing, but we also need to know how many pages we got. We are still asuming that we are not using a custom loop and that the <strong>$pages</strong> variable (dont mix up with $paged) was not set when we called the script. If thats the case we can once again  make use of a global variable to get that number:</p>
<pre>if($pages == '')
{
    global $wp_query;
    $pages = $wp_query-&gt;max_num_pages;
    if(!$pages)
    {
        $pages = 1;
    }
}</pre>
<p>Now for the &#8220;Brainfuck&#8221; ;D</p>
<p>As you can see,  appart from a little bit of  logic and arithmetic we  only need a single wordpress specific function. Its called get_pagenum_link() and allows us to fetch the url of a wordpress page  by passing the number of the page: get_pagenum_link(2) would get the  link to blog overview page 2 in my afforementioned Habitat theme.</p>
<p>What is done now is a check based on quite a few if statements that asks which items to display, based on the variables we retrieved and set before. I usually do explain everything in detail but I think it wouldn&#8217;t make much sence in this case. if you are really interested in deciphering all of the if statements feel free to do so, you now know which value is stored within each variable so it shouldn&#8217;t take all too long <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>The CSS</h3>
<p>The CSS Part of our pagination is rather simple. By default we would get an HTML output similar to this:</p>
<pre>&lt;div class='pagination'&gt;
 &lt;span class='current'&gt;1&lt;/span&gt;
 &lt;a href="http://www.kriesi.at/blog/page/2"&gt;2&lt;/a&gt;
 &lt;a href="http://www.kriesi.at/blog/page/3"&gt;3&lt;/a&gt;
 &lt;a href="http://www.kriesi.at/blog/page/2"&gt;›&lt;/a&gt;
 &lt;a href="http://www.kriesi.at/blog/page/12"&gt;»&lt;/a&gt;
&lt;/div&gt;</pre>
<p>We only need a few css rules to style this</p>
<pre>.pagination {
clear:both;
padding:20px 0;
position:relative;
font-size:11px;
line-height:13px;
}

.pagination span, .pagination a {
display:block;
float:left;
margin: 2px 2px 2px 0;
padding:6px 9px 5px 9px;
text-decoration:none;
width:auto;
color:#fff;
background: #555;
}

.pagination a:hover{
color:#fff;
background: #3279BB;
}

.pagination .current{
padding:6px 9px 5px 9px;
background: #3279BB;
color:#fff;
}</pre>
<h3>Advanced: Custom Loops</h3>
<p>You might probably want to use a so called <a href="http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action">custom loop</a> anywhere on a page, a loop that is not stored in the default global $wp_query object we used to retrieve the number:</p>
<pre> $pages = $wp_query-&gt;max_num_pages;</pre>
<p>If thats the case you need to call the kriesi_pagination() function with the first parameter set.</p>
<p>So lets assume you are using a simple custom loop on your site:</p>
<pre>&lt;?php $additional_loop = new WP_Query("cat=1,2,3&amp;paged=$paged"); ?&gt;

&lt;?php while ($additional_loop-&gt;have_posts()) : $additional_loop-&gt;the_post(); ?&gt;
 &lt;!-- Show loop content... --&gt;
&lt;?php endwhile; ?&gt;</pre>
<p>You could then call the pagination function that way:</p>
<pre>kriesi_pagination($additional_loop-&gt;max_num_pages);</pre>
<p>Feel free to use this function within any personal or commercial template, any attribution is appreciated but of course not required <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin/feed</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Improve your WordPress Navigation Menu Output</title>
		<link>http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output</link>
		<comments>http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output#comments</comments>
		<pubDate>Sun, 18 Jul 2010 20:40:15 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=1059</guid>
		<description><![CDATA[Wordpress 3 has gone gold and ships with an amazing new menu manager that can be used to control the navigation menus of your website. This tutorial will teach you how to change the default output of this manager since getting a custom output can heavily improve the style of your themes. So first of all here is an <a href="http://www.kriesi.at/themes/avisio/">example of the wordpress menu</a> we want to build.]]></description>
			<content:encoded><![CDATA[<p>WordPress 3 has gone gold and ships with an amazing new menu manager that can be used to control the navigation menus of your website. This tutorial will teach you how to change the default output of this manager, since getting a custom output can heavily improve the style of your themes. So first of all here is an <a href="http://www.kriesi.at/themes/avisio/">example of the wordpress menu</a> we want to build.</p>
<p><span id="more-1059"></span></p>
<h2>How to display the content of the wordpress menu description field</h2>
<p>As you can see, instead of a simple list we got the menu item name and below that name is a small description of that menu item. This is currently a rather popular style that unfortunatley can&#8217;t be done out of the box by wordpress.</p>
<p>As you may already know, once you have created a menu at your wordpress backend at Appearance &gt; Menus you can use a wordpress function called <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a> within your template files to display those menus.</p>
<p>The problem is, the basic output would look something like this:</p>
<pre>&lt;ul id="menu-main"&gt;
    &lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#"&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#"&gt;Blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>With a basic unordered list like that its almost impossible to create such a menu. So we need to change the output to get this:</p>
<pre>&lt;ul id="menu-main"&gt;
     &lt;li&gt;&lt;a href="#"&gt;&lt;strong&gt;Home&lt;/strong&gt;&lt;span&gt;Starting the journey&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href="#"&gt;&lt;strong&gt;About&lt;/strong&gt;&lt;span&gt;What to expect&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href="#"&gt;&lt;strong&gt;Contact&lt;/strong&gt;&lt;span&gt;Get in touch!&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href="#"&gt;&lt;strong&gt;Blog&lt;/strong&gt;&lt;span&gt; Latest storys&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>The &lt;strong&gt; tags wrap arround the title whereas the description is put into the &lt;span&gt; tags. Those can be styled easily with CSS later on to create this special menu style.</p>
<h2>Preparing the backend</h2>
<p><img class="alignleft size-full wp-image-1063" title="Screen options" src="http://www.kriesi.at/wp-content/uploads/2010/07/screenshot-2010-07-18-um-21.55.29.png" alt="" width="296" height="105" />The first thing we need to do is to setup the menu properly in our backend. WordPress already comes with the option to add a description to each menu item, but it is hidden by default.</p>
<p>When you are at the Appearance &gt; Menus Site you need to look at the top right and you will notice a &#8220;Screen Option&#8221; tab. Click it and you will get the option to display several other input fields for each menu item, among them a checkbox to show the description.</p>
<p><a href="http://www.kriesi.at/wp-content/uploads/2010/07/screenshot-2010-07-18-um-22.44.321.png"><img class="alignleft size-medium wp-image-1070" title="Edit menu" src="http://www.kriesi.at/wp-content/uploads/2010/07/screenshot-2010-07-18-um-22.44.321-300x241.png" alt="" width="300" height="241" /></a>Once that is done,  if you start editing your items you will notice that you can now enter a description for each menu item.</p>
<p>By default wordpress adds a rather long description to menu items that are created by pages, I would recommend to just delete those enourmous novels and just add a few words just like I did.</p>
<p>Now that we have setup the data to display in our backend, its time to prepare the frontend to show that data.</p>
<h2>Editing the output by using a custom walker</h2>
<p>WordPress uses a special &#8220;<strong>Walker</strong>&#8221; class that iterates over each data record and then displays this record accordingly. The cool thing about that is that we can simply create our own <strong>custom walker</strong> extending that PHP class. That way we dont need to care about fetching the stuff from the database or preparing the data arrays. We only need to extend the part of the wordpress code that outputs the list. So open your functions.php file and add the following code:</p>
<pre>class description_walker extends Walker_Nav_Menu
{
      function start_el(&amp;$output, $item, $depth, $args)
      {
           global $wp_query;
           $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

           $class_names = $value = '';

           $classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes;

           $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
           $class_names = ' class="'. esc_attr( $class_names ) . '"';

           $output .= $indent . '&lt;li id="menu-item-'. $item-&gt;ID . '"' . $value . $class_names .'&gt;';

           $attributes  = ! empty( $item-&gt;attr_title ) ? ' title="'  . esc_attr( $item-&gt;attr_title ) .'"' : '';
           $attributes .= ! empty( $item-&gt;target )     ? ' target="' . esc_attr( $item-&gt;target     ) .'"' : '';
           $attributes .= ! empty( $item-&gt;xfn )        ? ' rel="'    . esc_attr( $item-&gt;xfn        ) .'"' : '';
           $attributes .= ! empty( $item-&gt;url )        ? ' href="'   . esc_attr( $item-&gt;url        ) .'"' : '';

           $prepend = '&lt;strong&gt;';
           $append = '&lt;/strong&gt;';
           $description  = ! empty( $item-&gt;description ) ? '&lt;span&gt;'.esc_attr( $item-&gt;description ).'&lt;/span&gt;' : '';

           if($depth != 0)
           {
                     $description = $append = $prepend = "";
           }

            $item_output = $args-&gt;before;
            $item_output .= '&lt;a'. $attributes .'&gt;';
            $item_output .= $args-&gt;link_before .$prepend.apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID ).$append;
            $item_output .= $description.$args-&gt;link_after;
            $item_output .= '&lt;/a&gt;';
            $item_output .= $args-&gt;after;

            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
            }
}</pre>
<p>So what does this Class do? This is basically the walker that wordpress is using (I just copied the source code) and added a few lines in the lower third for a better output: The walker now checks if a description is set, and if thats the case it wraps the description into a span tag and appends it to the navigation title.</p>
<p>The walker also checks if we are currently iterating over a sub menu item or a top level item, since our sub menu items do not need to display a description.</p>
<h2>The Function Call</h2>
<p>Now that we have created a custom walker we only need to tell wordpress that it should use our walker instead of its own. This can be easily done by calling the <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a> with the walker parameter set:</p>
<pre>wp_nav_menu( array(
 'container' =&gt;false,
 'menu_class' =&gt; 'nav',
 'echo' =&gt; true,
 'before' =&gt; '',
 'after' =&gt; '',
 'link_before' =&gt; '',
 'link_after' =&gt; '',
 'depth' =&gt; 0,
 'walker' =&gt; new description_walker())
 );
</pre>
<p>Thats it. Once that is done your menu will be output with a completly different code structure that you can easily style with CSS to fit your needs. Here is a short snippet to get you startet:</p>
<pre>.nav{
height:50px;
padding-left:13px;
margin:0;
padding:0;
list-style-type:none;
list-style-position:outside;
position:relative;
}

.nav a{
display:block;
float:left;
line-height:18px;
outline:medium none;
padding:2px 10px;
text-decoration:none;
width:95px;
min-height: 35px;
}

.nav li a strong {
display:block;
font-size:14px;
font-weight:normal;
}

.nav li a span {
display:block;
font-size:10px;
line-height:14px;
}
</pre>
<p>I hope you can utilize this knowledge to push the boundaries of beautiful wordpress generated menus <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output/feed</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>WordPress Tutorial: Simple Breadcrumb Navigation</title>
		<link>http://www.kriesi.at/archives/wordpress-tutorial-simple-breadcrumb-navigation</link>
		<comments>http://www.kriesi.at/archives/wordpress-tutorial-simple-breadcrumb-navigation#comments</comments>
		<pubDate>Wed, 10 Sep 2008 13:38:29 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[Breadcrumb]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=397</guid>
		<description><![CDATA[First Steps to create a simple and lightweight WordPress Breadcrumb Navigation]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.kriesi.at/archives/wordpress-tutorial-simple-breadcrumb-navigation"><img class="alignleft size-full wp-image-398" src="http://www.kriesi.at/wp-content/uploads/2008/09/bread.jpg" alt="" width="100" height="100" /></a>I am currently working on some larger projects, and some of them are in desperate need of a <strong>breadcrumb navigation</strong>, since there are so many sub categories and pages, that users often have a hard time not to lose track of their current position on the site.</p>
<p>After searching the web for an adequate plugin, the only Breadcrumb navigation I could find was <a href="http://mtekk.weblogs.us/code/breadcrumb-navxt/">Breadcrumb NavXT</a>. The plugin is basically the only one which supports nested pages as well as nested categories. It has a ton of options&#8230; to my mind there are way to many. After testing the plugin on a blank installation my Database query count went from 17 to 59 even if I was on the starting page where no breadcrumb navigation was displayed. So I decided to code a lightweight version for myself.</p>
<p>What you will learn here, are the basics of creating a <strong>simple</strong> breadcrumb navigation. This tutorial doesn&#8217;t offer a complete script, just some snippets to experiment with =)</p>
<p><span id="more-397"></span>First of all here is the whole script:</p>
<pre>function my_breadcrumb() {
         if ( !is_front_page() ) {
		echo '&lt;p class="breadcrumb"&gt;&lt;span class="breadcrumb_info"&gt;You are here:&lt;/span&gt; &lt;a href="';
		echo get_option('home');
		echo '"&gt;';
		bloginfo('name');
		echo "&lt;/a&gt; &amp;raquo; ";
		}

		if ( is_category() || is_single() ) {
			$category = get_the_category();
			$ID = $category[0]-&gt;cat_ID;
			echo get_category_parents($ID, TRUE, ' &amp;raquo; ', FALSE );
		}

		if(is_single() || is_page()) {the_title();}
		if(is_tag()){ echo "Tag: ".single_tag_title('',FALSE); }
		if(is_404()){ echo "404 - Page not Found"; }
		if(is_search()){ echo "Search"; }
		if(is_year()){ echo get_the_time('Y'); }

		echo "&lt;/p&gt;";

          }</pre>
<p>I am using WordPress conditional Tags to check which section/post or page we are currently viewing. As you can see at the top, I don&#8217;t want to display the breadcrumb on the starting page. If we aren&#8217;t viewing the starting page, the first level &#8211; a link to the starting page &#8211; will be displayed.</p>
<pre>if ( is_category() || is_single() ) {
	        $category = get_the_category();
		$ID = $category[0]-&gt;cat_ID;
		echo get_category_parents($ID, TRUE, ' &amp;raquo; ', FALSE );
		}</pre>
<p>This is the trickiest part of the whole script since it uses some uncommon WordPress functions. It basically asks WordPress to display all parent categories of the current category/post. This way we can handle nested categories as well</p>
<p>If you want more information on <a href="http://codex.wordpress.org/Template_Tags/get_the_category">get_the_category</a> and <a href="http://codex.wordpress.org/Template_Tags/get_category_parents">get_category_parents</a> just check the WordPress Documentation =)</p>
<pre>if(is_single() || is_page()) {the_title();}
if(is_tag()){ echo "Tag: ".single_tag_title('',FALSE); }
if(is_404()){ echo "404 - Page not Found"; }
if(is_search()){ echo "Search"; }
if(is_year()){ echo get_the_time('Y'); }</pre>
<p>This one is pretty straight forward: We are using conditional comments again to handle some of the various scenarios like post, pages, tag and year archives, 404 sites etc.</p>
<p>If you want to create a script that can handle all possible scenarios you should check the <a href="http://codex.wordpress.org/Conditional_Tags">conditional tags reference</a> to see which cases need attention.</p>
<p>These short snippets should invite you to experiment a little bit since they can build the foundation to a complete lightweight breadcrumb script. It is far from complete now (nested pages don&#8217;t work, nested categories need a few tweaks, attachment handling is missing etc) but I guess its enough to start with <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
I am currently scripting a complete Breadcumb Navigation for my own and I am pretty satisfied with the outcome. It only needs some more minor tweaks to be ready for the public, but I dont&#8217;t know if I can spare some time in the upcoming future so I wanted to share these basics now, just in case you need them =)</p>
<p>What you can expect when my script is complete: a very lightweight breadcrumb script with little to no options but the possibilty to tweak it easily with little php knowledge, and the power to display a breadcrumb navigation without stressing your database (The NavXT-plugin uses about 40 queries, mine will use about 0-4)</p>
<p>Thanks to <a href="http://bueltge.de/brotkrumen-navi-fuer-wordpress/">Frank Bültge</a> for the inspiration <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/wordpress-tutorial-simple-breadcrumb-navigation/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>WordPress: Display Content in multiple Columns</title>
		<link>http://www.kriesi.at/archives/wordpress-display-content-in-multiple-columns</link>
		<comments>http://www.kriesi.at/archives/wordpress-display-content-in-multiple-columns#comments</comments>
		<pubDate>Mon, 21 Jul 2008 10:41:49 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=250</guid>
		<description><![CDATA[Learn how to modify the Wordpress function the_content() and display your WordPress content in multiple columns.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-259" src="http://www.kriesi.at/wp-content/uploads/2008/07/2columns.jpg" alt="" width="100" height="100" />Recently I had to create a website which displays the content in <strong>2 columns</strong>.</p>
<p>While CSS 3 is capable of doing this on its own with the new <a title="CSS3" href="http://www.w3.org/TR/2007/WD-css3-grid-20070905/">Grid Position Module</a>, a lot of browsers do not support this functions yet, so I needed to add a little extra markup to the output which is generated via the_content() to get the following result:</p>
<p><span id="more-250"></span></p>
<p><img class="alignleft size-full wp-image-251" src="http://www.kriesi.at/wp-content/uploads/2008/07/2column.jpg" alt="" width="512" height="142" /><br />
To get this result we need to <strong>filter the_content()</strong> before output with a custom function and add 2 divs to the output, which we style with CSS later on. So Ladys and Gentleman please open the <strong>functions.php</strong> file of your current WordPress Theme.</p>
<p>What functions.php does is let you create functions you can reuse in your theme. It works similar to a plugin file, being loaded when the theme is first loaded.</p>
<p>First of all: here you can see the whole code we need to filter our content, step by step description follows:</p>
<pre>function my_multi_col($content){
$columns = explode('&lt;h2&gt;', $content);

$i = 0;

	foreach ($columns as $column){
	if (($i % 2) == 0){
		$return .= '&lt;div class="content_left"&gt;' . "\n";
		if ($i &gt; 1){
		$return .= "&lt;h2&gt;";
	} else{
		$return .= '&lt;div class="content_right"&gt;' . "\n &lt;h2&gt;";
	}
		$return .= $column;
		$return .= '&lt;/p&gt;&lt;/div&gt;';
		$i++;
	}

	if(isset($columns[1])){
	    $content = wpautop($return);
	}else{
	    $content = wpautop($content);
	}
	echo $content;
}
add_filter('the_content', 'my_multi_col');</pre>
<p>What we do first is define a delimiter and split the whole content at specific points. I wanted to create a new column whenever a h2 tag was found.</p>
<pre>$columns = explode('&lt;h2&gt;', $content);</pre>
<p>The result is stored in an array which we will use to create a new $content string. To access each array item we will use a foreach loop:</p>
<pre>        $i = 0;

	foreach ($columns as $column){
        $i++;
	}</pre>
<p>You should have noticed the variable $i by now, we will use it to check if the current content part should be stored in a left column or right column div. To accomplish this we simply use the modulo operation ( $i % 2).</p>
<p>The modulo operator divides the first integer by the second and returns the remainder. Since we divide by 2 there are only 2 possible values to return: 0 and 1. If zero is returned we need a left content div, if 1 is returned a right content div:</p>
<pre>        $i = 0;
	foreach ($columns as $column){
            if (($i % 2) == 0){
                $return .= '&lt;div class="content_left"&gt;' . "\n";
            }else{
                $return .= '&lt;div class="content_right"&gt;' . "\n";
            }
        $i++;
	}</pre>
<p>Since the explode function we used earlier strips away our &lt;h2&gt; opening tags we need to add them to the code again, but we must be careful were to add them: We always need an opening tag in the right column and always need an opening tag in the left column except for the first time!</p>
<pre>$i = 0;

	foreach ($columns as $column){
	if (($i % 2) == 0){
		$return .= '&lt;div class="content_left"&gt;' . "\n";
		if ($i &gt; 1){
		$return .= "&lt;h2&gt;";
	} else{
		$return .= '&lt;div class="content_right"&gt;' . "\n &lt;h2&gt;";
	}

	}</pre>
<p>After adding the opening tags we simply put in the exploded $content parts and close the current &lt;p&gt; (automatically generated by WordPress) and &lt;div&gt; tag. After creating our new content string which is currently stored as a whole in $return we pass it to the wpautop which automatically adds formating to the string, store it in $content and then output it with echo, but ONLY if there was an h2 tag found. Otherwise we don&#8217;t need a second column and display the_content() without modifications.</p>
<pre>$i = 0;

	foreach ($columns as $column){
	if (($i % 2) == 0){
		$return .= '&lt;div class="content_left"&gt;' . "\n";
		if ($i &gt; 1){
		$return .= "&lt;h2&gt;";
	} else{
		$return .= '&lt;div class="content_right"&gt;' . "\n &lt;h2&gt;";
	}
		$return .= $column;
		$return .= '&lt;/p&gt;&lt;/div&gt;';
		$i++;
	}

        if(isset($columns[1])){
	    $content = wpautop($return);
	}else{
	    $content = wpautop($content);
	}	echo $content;
}</pre>
<p>Last but not least we have to tell WordPress when to activate our function. This is simply done with <a href="http://codex.wordpress.org/Plugin_API#Filters">&#8220;add_filter&#8221;</a></p>
<pre>add_filter('the_content', 'my_multi_col');</pre>
<p>Now whenever $content contains any h2 items they will be put in different divs . Just add some basic CSS and you are done:</p>
<pre>.content_right, .content_left{
float:left;
width:45%;
}

.content_left{
padding-right:5%;
}</pre>
<p>The function we created is far from perfect, but the main goal of this tutorial is to show you how you can modify the output of the WordPress generated content in an easy way. Have fun doing so <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/wordpress-display-content-in-multiple-columns/feed</wfw:commentRss>
		<slash:comments>73</slash:comments>
		</item>
		<item>
		<title>How to use WordPress Custom Fields</title>
		<link>http://www.kriesi.at/archives/how-to-use-wordpress-custom-fields</link>
		<comments>http://www.kriesi.at/archives/how-to-use-wordpress-custom-fields#comments</comments>
		<pubDate>Wed, 09 Jul 2008 15:31:29 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=246</guid>
		<description><![CDATA[Learn the basic principles of using WordPress Custom Fields, to create complex WordPress Themes.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-249" src="http://www.kriesi.at/wp-content/uploads/2008/07/custom.jpg" alt="" width="100" height="100" />WordPress gives an author the ability to add extra data to each written post and page. This data is called <strong>meta-data</strong> and is stored in <strong>custom fields</strong>.</p>
<p>These fields are really flexible in use and make it possible for developers and theme-authors to create stunning sites, far beyond from normal blog design.<span id="more-246"></span></p>
<p>In case you have never noticed it: to access these fields just head over to the write post/page site down to the Advanced Options Tabs. There you will find  the Custom Fields Tab which looks something like this:</p>
<p><img class="alignnone size-full wp-image-247" src="http://www.kriesi.at/wp-content/uploads/2008/07/customfields.jpg" alt="" width="500" height="401" /></p>
<p>Custom fields consist of two parts: <strong>A key and a value</strong>.</p>
<p>There are different options to display those fields, the one thing they all got in common: you have to call them inside the loop.</p>
<pre>&lt;?php the_meta(); ?&gt;</pre>
<p>This is the easiest way to display the data. The template tag automatically puts the entire meta-data into a CSS style called <tt>post-meta</tt>. The <strong>key</strong> is in a <tt>span</tt> called <tt>post-meta-key</tt>.</p>
<p>All of this is showcased in an unordered list:</p>
<pre>&lt;ul class='post-meta'&gt;
&lt;li&gt;&lt;span class='post-meta-key'&gt;mood:&lt;/span&gt; happy&lt;/li&gt;
&lt;li&gt;&lt;span class='post-meta-key'&gt;Weather:&lt;/span&gt; fine&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>You might want to use these custom informations in a more sophisticated way then displaying unordered lists with your mood and the current weather. Especially if you want to display a post in a way that doesn&#8217;t remind the visitor of a typical blog post, custom fields come in very handy.</p>
<p>Just take a look at my <a title="Portfolio" href="/portfolio">porfolio page</a>, or if you want to see a whole site based around custom fields, head over to <a title="Best Web Gallery" href="http://bestwebgallery.com/">BestWebGallery</a>. Each post is stuffed with a lot of meta data which is used to display the posts in an unique way.</p>
<p>To display the data in a superior way we use the function</p>
<pre> get_post_meta($post_id, $key, $single);</pre>
<p>The parameters we need to pass are explained fast:</p>
<ul>
<li>$post_id is the ID of the post which stores the meta data. Most of the time it is the current post and we use: <strong>$post-&gt;ID</strong></li>
<li><tt>$key</tt> is a string containing the name of the meta value you want.</li>
<li><tt>$single</tt> can either be <tt>true</tt> or <tt>false</tt>. If set to true then the function will return a single result, as a <strong>string</strong>. If false, or not set, then the function returns an <strong>array</strong> of the custom fields.This is needed if you have different $keys with the same name. We will set this to true for our example.</li>
</ul>
<p>So lets say we have a custom field named &#8220;image&#8221; which contains the URI to the image:<img class="alignnone size-full wp-image-248" src="http://www.kriesi.at/wp-content/uploads/2008/07/image1.jpg" alt="" width="494" height="113" /></p>
<p>we could easily display this image the following way:</p>
<pre>&lt;?php $image = get_post_meta($post-&gt;ID, 'Image', true); ?&gt;

&lt;img src="&lt;?php echo $image; ?&gt;" alt="" /&gt;</pre>
<p>There are many ways to use custom fields, another one would be to add  a different class to some of your posts:</p>
<pre>&lt;?php $additional_class = get_post_meta($post-&gt;ID, 'class', true); ?&gt;

&lt;div class="my_post &lt;?php echo $additional_class;?&gt; "&gt;
the_content();
&lt;/div&gt;
?&gt;</pre>
<p>The possibilitys are nearly endless, so let your creative juices flow and enhance your site with custom fields <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/how-to-use-wordpress-custom-fields/feed</wfw:commentRss>
		<slash:comments>75</slash:comments>
		</item>
		<item>
		<title>WordPress: how to separate comments and trackbacks</title>
		<link>http://www.kriesi.at/archives/wordpress-how-to-separate-comments-and-trackbacks</link>
		<comments>http://www.kriesi.at/archives/wordpress-how-to-separate-comments-and-trackbacks#comments</comments>
		<pubDate>Thu, 29 May 2008 19:20:25 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[trackbacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=223</guid>
		<description><![CDATA[Learn how to separate comments and trackbacks in WordPress so it is easy for your readers to follow ongoing conversations.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-224" src="http://www.kriesi.at/wp-content/uploads/2008/05/wp_seperate.jpg" alt="" width="100" height="100" />Today I read an interesting article on <a href="http://nettuts.com/">NETTUTS</a> which claims to <a title="NETTUTS" href="http://nettuts.com/news/unraveling-the-secrets-of-wordpress-commentsphp-file/">unravel the Secrets of WordPress &amp; Comments.php File</a>. This is actually pretty true, the author did a good job at explaining the different functions, comment loops, and form elements.</p>
<p>The one thing I really missed was an explanation on how to separate comments from trackbacks. Discussing on a blog with tons of trackback posts between the ongoing discussion is really annoying.</p>
<p><span id="more-223"></span></p>
<p>So here is my little addition to the NETTUTS tuorial:</p>
<h3>How to separate comments from trackbacks in WordPress</h3>
<p>First thing we need is a working peace of basic comment code, I&#8217;ll take the one from NETTUTS: (if you need any explanation on this piece of code, just read the aforementioned article)</p>
<pre>&lt;?php if($comments) : ?&gt;
&lt;ol&gt;
    &lt;?php foreach($comments as $comment) : ?&gt;
        &lt;li id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
            &lt;?php if ($comment-&gt;comment_approved == "0") : ?&gt;
            &lt;p&gt;Your comment is awaiting approval&lt;/p&gt;
        &lt;?php endif; ?&gt;
        &lt;?php comment_text(); ?&gt;
            &lt;cite&gt;&lt;?php comment_type(); ?&gt; by &lt;?php comment_author_link(); ?&gt; on &lt;?php comment_date(); ?&gt; at &lt;?php comment_time(); ?&gt;&lt;/cite&gt;
        &lt;/li&gt;
    &lt;?php endforeach; ?&gt;
&lt;/ol&gt;
&lt;?php else : ?&gt;
    &lt;p&gt;No comments yet&lt;/p&gt;
&lt;?php endif; ?&gt;</pre>
<p>Now we will use the function get_comment_type(); to check which kind of comment this is. The function returns one of three possible values: pingback, trackback or a comment.<br />
Our first target is to display only the comments. This is easily accomplished with an additional if statement:</p>
<pre>&lt;?php if($comments) : ?&gt;
&lt;ol&gt;
    &lt;?php foreach($comments as $comment) : ?&gt;
       &lt;?php if(get_comment_type() == "comment") : ?&gt;
            &lt;li id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
                &lt;?php if ($comment-&gt;comment_approved == "0") : ?&gt;
                &lt;p&gt;Your comment is awaiting approval&lt;/p&gt;
            &lt;?php endif; ?&gt;
            &lt;?php comment_text(); ?&gt;
                &lt;cite&gt;&lt;?php comment_type(); ?&gt; by &lt;?php comment_author_link(); ?&gt; on &lt;?php comment_date(); ?&gt; at &lt;?php comment_time(); ?&gt;&lt;/cite&gt;
            &lt;/li&gt;
        &lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
&lt;/ol&gt;
&lt;?php else : ?&gt;
    &lt;p&gt;No comments yet&lt;/p&gt;
&lt;?php endif; ?&gt;</pre>
<p>If you don&#8217;t want to display trackbacks you are done now. In case you want to show them, you have to call the comment loop a second time, this time only displaying the comment, if get_comment_type() returns pingback or trackback.</p>
<pre>&lt;?php if($comments) : ?&gt;
&lt;ol&gt;
    &lt;?php foreach($comments as $comment) : ?&gt;
        &lt;?php if((get_comment_type() == "pingback") || (get_comment_type() == "trackback")) : ?&gt;
            &lt;li id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
                &lt;?php comment_author_link() ?&gt;&lt;/li&gt;
            &lt;/li&gt;
        &lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
&lt;/ol&gt;
&lt;?php endif; ?&gt;</pre>
<p>Thats it, not that hard to master and a big improvement in readability for your ongoing discussions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/wordpress-how-to-separate-comments-and-trackbacks/feed</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Admin login on your front page</title>
		<link>http://www.kriesi.at/archives/admin-login-on-your-front-page</link>
		<comments>http://www.kriesi.at/archives/admin-login-on-your-front-page#comments</comments>
		<pubDate>Fri, 23 May 2008 12:05:14 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=217</guid>
		<description><![CDATA[Learn how to skip the WordPress login page and create a working login form on your front page, in your sidebar or footer.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-220" src="http://www.kriesi.at/wp-content/uploads/2008/05/tutorial_preview.jpg" alt="" width="100" height="100" />Last week I showed you <a title="How to create a frontend admin menu" href="http://www.kriesi.at/archives/frontend-admin-menu-in-wordpress">how to create a menu which reveals itself only to logged in users</a>, utilizing the WordPress function current_user_can(). Today we will take this one step further and create a Login form for your users, which can be placed in your sidebar, footer or anywhere else on your page.</p>
<p><span id="more-217"></span></p>
<p>The final result would look something like this on a WordPress default installation:<br />
<img class="alignleft size-full wp-image-218" src="http://www.kriesi.at/wp-content/uploads/2008/05/login-1.jpg" alt="" width="490" height="217" /></p>
<p><img class="alignleft size-full wp-image-219" src="http://www.kriesi.at/wp-content/uploads/2008/05/login-2.jpg" alt="" width="490" height="217" /></p>
<h4>So what we want to display is:</h4>
<ol>
<li>An input field for user name</li>
<li>An input field for password</li>
<li>A checkbox for remembering the user</li>
<li>A hidden field which tells WordPress where to redirect the User after login took place</li>
<li>A Submit Button</li>
<li>2 Links: One for password recovery, one for new registration</li>
</ol>
<p>Since we want to make the form work in every template we will make use of the function <strong>get_option(&#8216;home&#8217;)</strong> which gets the the full path to your WordPress installation.</p>
<pre>&lt;h3&gt;Login&lt;/h3&gt;
&lt;form action="&lt;?php echo get_option('home'); ?&gt;/wp-login.php" method="post"&gt;

    &lt;p&gt;&lt;label for="log"&gt;User&lt;/label&gt;&lt;input type="text" name="log" id="log" value="&lt;?php echo wp_specialchars(stripslashes($user_login), 1) ?&gt;" size="20" /&gt; &lt;/p&gt;

    &lt;p&gt;&lt;label for="pwd"&gt;Password&lt;/label&gt;&lt;input type="password" name="pwd" id="pwd" size="20" /&gt;&lt;/p&gt;

    &lt;p&gt;&lt;input type="submit" name="submit" value="Send" class="button" /&gt;&lt;/p&gt;

    &lt;p&gt;
       &lt;label for="rememberme"&gt;&lt;input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /&gt; Remember me&lt;/label&gt;
       &lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;" /&gt;
    &lt;/p&gt;
&lt;/form&gt;
&amp;s
&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-register.php"&gt;Register&lt;/a&gt;
&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-login.php?action=lostpassword"&gt;Recover password&lt;/a&gt;</pre>
<p>Into the hidden field, we put the URL of the page the user used to log in, so he is redirected to this page again after authentication.</p>
<p>Since we only want to show this code if the user is not already logged in, we use the function current_user_can() , with a parameter of level_0. (in case you dont understand what that means <a title="How to create a frontend admin menu" href="http://www.kriesi.at/archives/frontend-admin-menu-in-wordpress">check my last tutorial about current_user_can</a>)</p>
<pre>&lt;?php if (!(current_user_can('level_0'))){ ?&gt;
    &lt;h3&gt;Login&lt;/h3&gt;
    &lt;form code from above etc&gt;
&lt;?php } else { /*next to come*/}?&gt;</pre>
<p>The next thing to do is writing the code for logged in users. For this purpose I just take a slightly modified version of last weeks tutorial (mentioned above) and put it in the else condition. Here is how the whole thing looks like, just in case you only want to copy/paste it <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre>&lt;?php if (!(current_user_can('level_0'))){ ?&gt;
&lt;h3&gt;Login&lt;/h3&gt;
&lt;form action="&lt;?php echo get_option('home'); ?&gt;/wp-login.php" method="post"&gt;

    &lt;p&gt;&lt;label for="log"&gt;User&lt;/label&gt;&lt;input type="text" name="log" id="log" value="&lt;?php echo wp_specialchars(stripslashes($user_login), 1) ?&gt;" size="20" /&gt; &lt;/p&gt;

    &lt;p&gt;&lt;label for="pwd"&gt;Password&lt;/label&gt;&lt;input type="password" name="pwd" id="pwd" size="20" /&gt;&lt;/p&gt;

    &lt;p&gt;&lt;input type="submit" name="submit" value="Send" class="button" /&gt;&lt;/p&gt;

    &lt;p&gt;
       &lt;label for="rememberme"&gt;&lt;input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /&gt; Remember me&lt;/label&gt;
       &lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;" /&gt;
    &lt;/p&gt;
&lt;/form&gt;

&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-register.php"&gt;Register&lt;/a&gt;
&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-login.php?action=lostpassword"&gt;Recover password&lt;/a&gt;
&lt;?php } else { ?&gt;
        &lt;ul class="admin_box"&gt;
            &lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-admin/"&gt;Dashboard&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-admin/post-new.php"&gt;Write new Post&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-admin/page-new.php"&gt;Write new Page&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-login.php?action=logout&amp;redirect_to=&lt;?php echo urlencode($_SERVER['REQUEST_URI']) ?&gt;"&gt;Log out&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;

&lt;?php }?&gt;</pre>
<p>Voila, your front page login is ready to use <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h3>Update for wordpess 2.7</h3>
<p>If your are using wordpress 2.7 you have to exchange the old logout link with the new version:</p>
<pre>&lt;a href="&lt;?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?&gt;logout&lt;/a&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/admin-login-on-your-front-page/feed</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Frontend Admin Menu in WordPress</title>
		<link>http://www.kriesi.at/archives/frontend-admin-menu-in-wordpress</link>
		<comments>http://www.kriesi.at/archives/frontend-admin-menu-in-wordpress#comments</comments>
		<pubDate>Sun, 04 May 2008 14:30:43 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=211</guid>
		<description><![CDATA[Learn how to build a WordPress menu that reveals itself only to logged in users, editors or administrators.]]></description>
			<content:encoded><![CDATA[<p>Here is a short tutorial on how to create an additional WordPress menu that only shows up if a user is logged in. I use this technique to create admin front end interface menus for the most used tasks: writing and editing posts and pages, editing the current post , a direct link to the &#8220;manage&#8221; Section of the  WordPress admin Interface etc.</p>
<p><span id="more-211"></span></p>
<p>Here are 2 screenshots of the right top of my header graphic. The first one is what everybody  else sees.<img class="alignnone size-full wp-image-213 alignleft" style="float: left" src="http://www.kriesi.at/wp-content/uploads/2008/05/menue_no.jpg" alt="" width="490" height="279" /><br />
And this is what I see as long as I am logged in:<br />
<img class="alignnone size-full wp-image-214 alignleft" style="float: left" src="http://www.kriesi.at/wp-content/uploads/2008/05/menue_yes.jpg" alt="" width="490" height="279" /> This is easily done with the WordPress function <strong>current_user_can()</strong></p>
<p>As a parameter for the function you just have to add the expected user level and wrap the whole function call in an if statement.</p>
<pre>&lt;?php
        if (current_user_can('level_10')){
        /*do something*/
        }
?&gt;</pre>
<p>The /*do something*/ code would now only be added/executed if the user has a status of level 10, thus is an administrator. To get more information on User Levels check the <a title="Roles and Capabilities" href="http://codex.wordpress.org/Roles_and_Capabilities">WordPress Documentation</a>.<br />
Here is a short list of the user capabilities, just in case you don&#8217;t really care and only want to add a menue for a specific user group:</p>
<ul>
<li><strong>Subscriber : </strong>level_0</li>
<li><strong>Contributor: </strong>level_1</li>
<li><strong>Author: </strong>level_2</li>
<li><strong>Editor: </strong>level_3 &#8211; level_7</li>
<li><strong>Administrator: </strong>level_8 &#8211; level_10</li>
</ul>
<p>Last but not least a short example of how an admin menu could look like:</p>
<pre>&lt;?php
    if (current_user_can('level_10')){ ?&gt;
        &lt;ul class="admin_box"&gt;
            &lt;?php wp_register(); ?&gt;
            &lt;li&gt;&lt;?php wp_loginout(); ?&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-admin/post-new.php"&gt;Write new Post&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/wp-admin/page-new.php"&gt;Write new Page&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;do something&lt;/li&gt;
            &lt;li&gt;do something&lt;/li&gt;
        &lt;/ul&gt;
&lt;?php }?&gt;</pre>
<p>Have fun creating your own user related menus <img src='http://www.kriesi.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/frontend-admin-menu-in-wordpress/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>How to modify your WordPress RSS Feed</title>
		<link>http://www.kriesi.at/archives/how-to-modify-your-wordpress-rss-feed</link>
		<comments>http://www.kriesi.at/archives/how-to-modify-your-wordpress-rss-feed#comments</comments>
		<pubDate>Sun, 27 Apr 2008 17:13:47 +0000</pubDate>
		<dc:creator>Kriesi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress Tutorial]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.kriesi.at/?p=206</guid>
		<description><![CDATA[Learn how to exclude categories in various ways from the Wordpress generated RSS Feed.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-207" src="http://www.kriesi.at/wp-content/uploads/2008/04/wordpressfeed.jpg" alt="" width="100" height="100" />I for myself really enjoy using WordPress as a Content Management System, since most of the time its really easy to adapt to my needs. I usually use the different categories on my sites to display the various sections of the sites. For example, kriesi.at uses the category &#8220;tutorials&#8221; to feed the <a href="/resources">resources</a> page and the &#8220;portfolio&#8221; category to feed my <a title="Portfolio" href="/portfolio">online portfolio</a>.</p>
<p>This is easily accomplished by using the <a title="Wordpress.org docs: Query Posts" href="http://codex.wordpress.org/Template_Tags/query_posts">query_posts()</a> function of WordPress which i won&#8217;t discuss in detail since the documentations are pretty comprehensive.</p>
<p>The problem I recently encountered is that the WordPress generated rss feed must be modified as well, otherwise it will display every post in each category. A user subscribing to my blog feed doesn&#8217;t want to be bothered with portfolio entrys, so I searched for a way to exclude categories from the main feed. There are basically two solutions I could find:</p>
<ol>
<li>Exclude the Categories via URL</li>
<li>Exclude the Categories through using a small function</li>
</ol>
<p>Both ways are really simple:</p>
<p>If you want to exclude a category you first have to know the ID of course. In WordPress versions prior to 2.5 you could just get it in your admin panels &#8220;manage&#8221; -&gt; &#8220;categories&#8221; section. Post 2.5 versions do not display the category ID anymore but you can get it by hovering over the category name and extracting it from the link URL. Its the cat_ID attribute.</p>
<p>Say you want to exclude category 20 you just append ?cat=-20 to your feed url.</p>
<p>Example:</p>
<ul>
<li>normal feed: http://www.kriesi.at/feed</li>
<li>modified feed: http://www.kriesi.at/feed<strong>?cat=-20</strong></li>
<li>want to exclude more categories: http://www.kriesi.at/feed<strong>?cat=-20&amp;cat=-21&amp;cat=-22</strong></li>
</ul>
<p>Well these URLs are not what i would consider beautiful so you might use a service like <a title="Feedburner" href="http://www.feedburner.com/">feedburner</a> to create a nice looking feed out of it. But beware, feedburner expects a slightly different syntax; insted of using ampersands you have to use commas:</p>
<p>So if you want to exclude a WordPress category from the Feedburner feed do it this way:</p>
<p>http://www.kriesi.at/feed<strong>?cat=-20,-21,-22</strong></p>
<p>If you dont&#8217;t like this way of excluding you can use a small function instead. Just add the following code anywhere to your templates functions.php:</p>
<pre>function my_cat_exclude($query) {
    if ($query-&gt;is_feed) {
        $query-&gt;set('cat','-20,-21,-22');
    }
    return $query;
}

add_filter('pre_get_posts','my_cat_exclude');</pre>
<p>This function will strip the categories you define out of your RSS Feed without the need of adjusting your url.<br />
A clean and simple way but not as flexible as using URLs if you want to provide more than one feed.</p>
<p>Hope this helps you if you ever need to modify your feed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kriesi.at/archives/how-to-modify-your-wordpress-rss-feed/feed</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
	</channel>
</rss>

