<?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>SofaRider &#187; how-to</title>
	<atom:link href="http://rider.sofarider.com/tag/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://rider.sofarider.com</link>
	<description>WordPress Themes, Widgets, Development &#124; WEB &#38; Graphic Design</description>
	<lastBuildDate>Wed, 14 Oct 2009 08:40:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to fix get_the_content() stripped tags?</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-fix-get_the_content-stripped-tags/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-fix-get_the_content-stripped-tags/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 06:49:04 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[get_the_content()]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[missing tags]]></category>
		<category><![CDATA[stripped tags]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=293</guid>
		<description><![CDATA[This is the problem I came across recently and I am still not sure whether this is a kind of intentional bug or else because it just looks like so. OK, what exactly happens when you use WordPress get_the_content() function in order to &#8217;save&#8217; Post or Page content into variable? You can do a little [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/09/1201373442_anus-200x200.jpg" alt="1201373442_anus" title="1201373442_anus" width="200" height="200" class="alignnone size-thumbnail wp-image-294" />This is the problem I came across recently and I am still not sure whether this is a kind of intentional bug or else because it just looks like so. OK, what exactly happens when you use WordPress <strong>get_the_content()</strong> function in order to &#8217;save&#8217; Post or Page content into variable? You can do a little test. Somewhere in your Post details, after <strong>the_content()</strong> function try to add the following code &#8211; just to compare what&#8217;s happening on frontend:</p>
<pre>
<code>
&lt;?php
	the_content(); // this is your standard way to output Post or Page content
	// now the test
	$var_content = get_the_content();
	echo $var_content;
?&gt;
</code>
</pre>
<p>It looks like paragraphs and break rules (&lt;p&gt; and &lt;br /&gt;) are gone. Maybe some other tags too but I have noticed those two. I suppose not so many developers use <strong>get_the_content()</strong> function, however some of my themes (this one too) needs it in order to extract images or documents out of Post/Page content and still keep text formatted. We all know that <strong>the_excerpt()</strong> function will strip down each and every html tag so there&#8217;s no sense in using it, especially not in Post/Page details template.</p>
<h2>Solution</h2>
<p>It&#8217;s true there&#8217;s a solution at codex.wordpress.org but for those who have hard time to find it &#8211; here it is:</p>
<pre>
<code>
&lt;?php
	the_content(); // this is your standard way to output Post or Page content
	// now the test which works
	$var_content = get_the_content();
	$var_content = apply_filters( 'the_content', $var_content );
	$var_content = str_replace( ']]&gt;', ']]&gt;', $var_content );
	echo $var_content;
?&gt;
</code>
</pre>
<p>It should be OK now. Just wanted to pay your attention to this issue since WordPress developer team didn&#8217;t fix it until 2.8.4 &#8211; currently available for download. Maybe next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-fix-get_the_content-stripped-tags/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress &#8211; simple site map code</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/wordpress-simple-site-map-code/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/wordpress-simple-site-map-code/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 06:41:49 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[site map]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=284</guid>
		<description><![CDATA[Recently I&#8217;ve been proposed to add a sitemap template page (read functionality) to one of my WordPress themes. I started to Google for it but none of available plugins or code snippets didn&#8217;t do well. What my client actually wanted to have was something similar to a tree system where folders would represent categories/sub-categories and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/09/tree-200x200.png" alt="tree" title="tree" width="200" height="200" class="alignnone size-thumbnail wp-image-283" />Recently I&#8217;ve been proposed to add a sitemap template page (read functionality) to one of my WordPress themes. I started to Google for it but none of available plugins or code snippets didn&#8217;t do well. What my client actually wanted to have was something similar to a tree system where folders would represent categories/sub-categories and files would &#8216;become&#8217; Post titles. So, here&#8217;s the result of a really simple site map generator for any WordPress theme.<br />
I do not claim it&#8217;s perfect and I&#8217;m aware it needs certain improvements but I guess it&#8217;s quite good for that purpose.</p>
<h2>The code</h2>
<p>Please note that I have created new WordPress template file and save it as &#8217;sitemap.php&#8217; in theme&#8217;s root folder. For more info regarding custom WP template files and how to use them, please refer to <a href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates" target="_blank">this page</a>.<br />
Also, another important info is that this code will work only for Custom Permalink structure set to <strong>/%category%/%postname%/</strong>.</p>
<pre>
<code>
&lt;?php
    // easy job for pages...
    echo '&lt;ul&gt;';
    echo '&lt;li&gt;&lt;h1&gt;PAGES:&lt;/h1&gt;&lt;/li&gt;';
    echo '&lt;li&gt;&lt;ul&gt;';
    wp_list_pages( 'title_li=&amp;echo=1' );
    echo '&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;';

    // categories sitemap will be tough...get'em all
    $subcats = wp_list_categories( 'echo=0&amp;use_desc_for_title=0&amp;title_li=' );
    // anybody there?
    preg_match_all( '|&lt;a.*?href=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $subcats, $m );
	if( !$m[ 1 ] ) {
		// no categs, subcategs or whatsoever...
		echo &quot;There are no categories added to your WordPress site.&quot;;
	} else {
		$arr_categories = array();
		$arr_orig_urls  = array();
		foreach( $m[ 1 ] as $key =&gt; $value ) {
			// $value will keep the URL, extract category slug
			$arr_of_url = explode( '/', $value );
			array_pop( $arr_of_url ); // remove empty
			// push the last
			array_push( $arr_categories, $arr_of_url[ count( $arr_of_url ) - 1 ] );
			// get its URL
			array_push( $arr_orig_urls, $value );
		}
	}

	if( count( $arr_categories ) &gt; 0 ) {
		// now we have entire logical structure of all categories
		// let's try to get ID for each of these
		echo '&lt;ul&gt;';
		echo '&lt;li&gt;&lt;h1&gt;CATEGORIES:&lt;/h1&gt;&lt;/li&gt;';
		$i = 0;
		while( $i &lt; count( $arr_categories ) ) {
			// shortcut by WP built-in
			$idObj = get_category_by_slug( $arr_categories[ $i ] );
			$catid = $idObj-&gt;term_id;

			// check whether this is root category. If true, make an outset in list, otherwise leave inset.
			if( $idObj-&gt;category_parent &gt; 0 ) echo '&lt;li&gt;&lt;ul&gt;';

			// get category real name and link
			$cat_real_name = $wpdb-&gt;get_var( &quot;SELECT name FROM $wpdb-&gt;terms WHERE term_id=&quot; . $catid );
			echo '&lt;li&gt;&lt;h2&gt;&lt;a href=&quot;' . $arr_orig_urls[ $i ] . '&quot;&gt;' . $cat_real_name . '&lt;/a&gt;&lt;/h2&gt;&lt;/li&gt;';

			// generate list of posts
			echo '&lt;li&gt;&lt;ul&gt;';
			query_posts( 'cat=' . $catid  . '&amp;order=ASC' ); // change to DESC - if required
			while( have_posts() ) : the_post();
?&gt;

&lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
&lt;?php
			endwhile;
			echo '&lt;/ul&gt;&lt;/li&gt;';
			if( $idObj-&gt;category_parent &gt; 0 ) echo '&lt;/ul&gt;&lt;/li&gt;';
			$i ++;
		}
	echo '&lt;/ul&gt;';
	}
?&gt;
</code>
</pre>
<p>Hopefully you will find this code useful. Any comment/suggestion regarding improvement is welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/wordpress-simple-site-map-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to connect WordPress and Flash &#8211; part #2</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-2/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-2/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 08:32:45 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[wordpress flash]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=267</guid>
		<description><![CDATA[Finally, part 2 of this tutorial is here. Part 1 can be seen HERE. There you can find out how to prepare and format data for Flash and now we are about to do something with it. I&#8217;ve made a package of all required files for download so you can see what else will be [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-thumbnail wp-image-170" title="2connection-done-big" src="http://rider.sofarider.com/wp-content/uploads/2009/06/2connection-done-big-200x200.jpg" alt="2connection-done-big" width="200" height="200" />Finally, part 2 of this tutorial is here. Part 1 can be seen <a href="http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-1/">HERE</a>. There you can find out how to prepare and format data for Flash and now we are about to do something with it. I&#8217;ve made a package of all required files for download so you can see what else will be used. Please <a href="http://rider.sofarider.com/wp-content/uploads/2009/07/WP_flash.zip">download ZIP</a>, unpack and open <strong>WP_flash.fla</strong>. Code is well commented and I am not about to explain how and why. This is just an example of my own implementation, you may develop your own and display data differently in Flash. My goal was to demonstrate WP &#8211; Flash data exchange on the simplest possible way.</p>
<h2>How to use it?</h2>
<p>Just for demo purpose upload all the files (and &#8217;script&#8217; folder as well!) to the root of your theme, it doesn&#8217;t matter which one. Now you need to call &#8216;WP_flash_holder.php&#8217; in Browser but full path to this file must be used because we are currently out of WP &#8216;native environment&#8217;:<br />
<strong>http://yourdomain.com/wp-content/themes/your_theme_name/WP_flash_holder.php</strong>.<br />
For a case you are about to include <strong>WP_flash.swf</strong> in any existing template file of your theme (for example <strong>sidebar.php</strong>), things will work normally.</p>
<p>NOTE:</p>
<p>Open <strong>WP_flash_holder.php</strong> and change path to match your domain and theme name otherwise it&#8217;ll not work. For example the line reading:</p>
<pre><code>
&lt;script src="http://your_domain.com/wp-content/themes/your_theme_name/script/swfobject.js" type="text/javascript"&gt;&lt;/script&gt;
</code></pre>
<p>As well as:</p>
<pre><code>
var so = new SWFObject( "http://your_domain.com/wp-content/themes/your_theme_name/WP_flash.swf", "wpflash", "550", "400", "8" );
</code></pre>
<p>&#8230;must be replaced with your own data!</p>
<h2>Files in package&#8230;</h2>
<ul>
<li> <strong>slidestyle.css<br />
</strong>Flash Player supports a subset of properties in the original CSS1 specification only so basic text formatting can be done here. Not much but enough for this tutorial.</li>
<li> <strong>WP_flash_holder.php </strong><br />
This file is here just to properly include/embed Flash file into HTML page. In source code you can read how to include Flash in native WordPress environment (for example <strong>sidebar.php</strong>).</li>
<li> <strong>script &gt; swfobject.js </strong><br />
As already mentioned, swf must be properly embed so this is nothing but a piece of javascript code required to avoid page errors and Browser warnings.</li>
<li> <strong>WP_flash.fla</strong> and <strong>WP_flash.swf</strong><br />
Source and rendered file used for demonstration purpose.</li>
</ul>
<h2>It&#8217;s good to know</h2>
<p>I guess some of you already plan to make a first Flash theme so it&#8217;s good to know that each and every WP theme must fulfill minimum requirements. Theme folder MUST contain the following files: <strong>index.php</strong>, <strong>style.css</strong> and <strong>functions.php</strong> (screenshot.png). In that case you can keep all of your Flash styles in <strong>style.css</strong> and embed Flash into <strong>index.php</strong>. Remember, it&#8217;s a long way to develop Flash theme and this tutorial is just a little tiny foot step on the long path up to the hill. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to add teaser image next to post title</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-add-an-image-teaser-next-to-post-title/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-add-an-image-teaser-next-to-post-title/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 06:52:11 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[extract image]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[teaser image]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[wordpress title image]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=245</guid>
		<description><![CDATA[Recently I&#8217;ve received an email regarding those little thumbnails next to Post title. My mate asked me to explain how to set it up so here&#8217;s the &#8216;trick&#8217;. As you may note, teaser thumb in this Post will only be displayed once. There&#8217;s no duplicate within the content in spite of the fact that you [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/gorilla-200x200.jpg" alt="gorilla" title="gorilla" width="200" height="200" class="alignnone size-thumbnail wp-image-246" />Recently I&#8217;ve received an email regarding those little thumbnails next to Post title. My mate asked me to explain how to set it up so here&#8217;s the &#8216;trick&#8217;. As you may note, teaser thumb in this Post will only be displayed once. There&#8217;s no duplicate within the content in spite of the fact that you upload teaser image along with the rest of the content and all other images related to it. Yes, no Custom Fields involved here at all!</p>
<blockquote><p>Otherwise spoken, how to extract certain image out of the post and display it out of context.</p></blockquote>
<p>So how the hell WordPress can know which image is supposed to represent teaser image if there&#8217;s at least one image extra attached to the very same Post? Well, that&#8217;s the trick. <strong>We must use different &#8220;insert&#8221; method</strong>. Let&#8217;s assume all other images are clickable and users are able to see full size for each of them. In order to properly extract teaser image from Post later in frontend we&#8217;ll use the following method to insert it first:<br />
<a href="http://rider.sofarider.com/wp-content/uploads/2009/07/ill_post.png" rel="shadowbox[post-245];player=img;"><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/ill_post.png" alt="ill_post" title="ill_post" width="588" height="343" class="alignnone size-full wp-image-248" /></a><br />
If you take a look at the HTML code after, you&#8217;ll note that this image is not enclosed with &lt;a&gt;&lt;/a&gt; tags, right? Let&#8217;s now take a look how to extract such image from the content&#8230;</p>
<h2>Extracting teaser image from Post</h2>
<p>The basic idea is to grab teaser thumbnail from the_content() and replace it with &#8211; nothing, empty string. Remember, we don&#8217;t want to have the same image displayed twice within Post.</p>
<pre>
<code>
&lt;?php
    // get the first image out of content, prevent double image display
    $path = &quot;&quot;; // teaser image path
    $content = get_the_content(); // get Post content entirely
    // grab fist image (teaser thumb) by pattern
    $frst_image = preg_match_all( '|&lt;img.*?src=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $content, $matches );
    // any image there?
    if( $frst_image &gt; 0 ) {
    	$path = $matches[ 1 ][ 0 ]; // we need the first one only!
    	// replace with empty string in order to avoid duplicates
    	$content = preg_replace( '|&lt;img.*?src=[\'&quot;](' . $path . ')[\'&quot;].*?&gt;|i', '', $content );
    }
    if( $path ) {
    	// teaser image found! display it now or leave in variable for later
?&gt;
    	&lt;img src=&quot;&lt;?php echo $path; ?&gt;&quot; alt=&quot;&lt;?php echo get_the_title(); ?&gt;&quot; class=&quot;thumbnail&quot; /&gt;
&lt;?php
    	$path = &quot;&quot;;
    } else {
    	// teaser image not found. replace with dummy graphic
?&gt;
    	&lt;img src=&quot;&lt;?php echo bloginfo( 'template_directory' ) . ( '/images/no_image.jpg' ); ?&gt;&quot; alt=&quot;&lt;?php echo get_the_title(); ?&gt;&quot; class=&quot;thumbnail&quot; /&gt;
&lt;?php
    	$path = &quot;&quot;;
    }
?&gt;
</code>
</pre>
<p>There&#8217;s one little tip at the end: Insert teaser images before any other Post content (text or other images). It&#8217;s good idea to keep things organized.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-add-an-image-teaser-next-to-post-title/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to build sequential navigation in WordPress</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-build-sequential-navigation-in-wordpress/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-build-sequential-navigation-in-wordpress/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 07:56:24 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[sequential]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress navigation]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=226</guid>
		<description><![CDATA[What is exactly &#8217;sequential navigation&#8217;? From the navigation point of view, imagine category which has &#8216;n&#8217; number of sub-categories and each of these sub-categories may have &#8216;n&#8217; number of sub-sub-categories&#8230;etc. From programmer&#8217;s point of view it&#8217;s a nested list whose list item may contain another nested list and so on. Personally, I&#8217;m not a fan [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/naef_animal_puzzle_LRG-200x200.jpg" alt="naef_animal_puzzle_LRG" title="naef_animal_puzzle_LRG" width="200" height="200" class="alignnone size-thumbnail wp-image-228" />What is exactly &#8217;sequential navigation&#8217;? From the navigation point of view, imagine category which has &#8216;n&#8217; number of sub-categories and each of these sub-categories may have &#8216;n&#8217; number of sub-sub-categories&#8230;etc. From programmer&#8217;s point of view it&#8217;s a nested list whose list item may contain another nested list and so on. Personally, I&#8217;m not a fan of nested list, it makes the site ugly. Branched or multi-level drop-down menu is OK, however it keeps child categories/pages always hidden.</p>
<p>
And here it comes sequential navigation as quite handy solution. I like to use it in conjunction with <a href="http://rider.sofarider.com/blog/wordpress-tips/easy-breadcrumbs/">breadcrumbs</a> so there&#8217;s no chance site visitor gets &#8216;lost&#8217;. As you know, in WordPress categories and pages can have &#8216;children&#8217;, up to 999 levels &#8211; as I recall &#8211; please correct me if I am wrong. Of course, you&#8217;ll never need so many navigation levels but I&#8217;m sure 3 are quite often.
</p>
<p>
Before showing the code, I would like to explain the logic behind sequential navigation. Here&#8217;s an illustration &#8211; just to show you what we are up to.<br />
<a href="http://rider.sofarider.com/wp-content/uploads/2009/07/sequential_navig.png" rel="shadowbox[post-226];player=img;"><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/sequential_navig.png" alt="sequential_navig" title="sequential_navig" width="598" height="329" class="alignnone size-full wp-image-227" /></a>
</p>
<blockquote><p>Our goal is to display only the first level children of selected category, no matter how &#8216;deep&#8217; we are.</p></blockquote>
<p>
Parent category (or page) will always be displayed as a title, indicating current menu set. Hopefully it does make sense to you. It doesn&#8217;t? Later you will be able to read how easily is to implement it into your own site&#8230;
</p>
<h2>The code</h2>
<p>Code is well commented so there shouldn&#8217;t be a problem to understand the logic&#8230;</p>
<pre>
<code>
&lt;?php
	// is there a page or category? both may have childeren
	if( is_category() ) {
		// if this category has childeren
		$categ_object = get_category( get_query_var( 'cat' ), false );
		$list_subcats = wp_list_categories( 'title_li=&amp;depth=1&amp;echo=0&amp;child_of=' . (int)$categ_object-&gt;cat_ID );
		// wordpress never returns null or empty string. If children, &lt;a&gt; tag will be found, otherwise string is returned.
		preg_match_all( '|&lt;a.*?href=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $list_subcats, $m );
		if( !$m[ 1 ] ) {
			// there are no subcategories. Why?
			// this is either the last child or this category really doesn't have subcategories
			// last child must have a parent, right?
				if( (int)$categ_object-&gt;category_parent &gt; 0 ) {
					// we'll need parent category name for the title, extract name via category ID
					$parent_cat_name = $wpdb-&gt;get_var( &quot;SELECT name FROM $wpdb-&gt;terms WHERE term_id=&quot; . (int)$categ_object-&gt;category_parent );
?&gt;
					&lt;div class=&quot;box&quot;&gt;
					&lt;h1&gt;&lt;?php echo $parent_cat_name; ?&gt;&lt;/h1&gt;
					&lt;ul class=&quot;subnavigation&quot;&gt;
					&lt;?php wp_list_categories( 'title_li=&amp;depth=1&amp;child_of=' . (int)$categ_object-&gt;category_parent ); ?&gt;
					&lt;/ul&gt;
					&lt;/div&gt;
&lt;?php
				} // else...no else! This category really doesn't have child categories.
		} else {
			// ohoho! ...but here are some. List them all...
?&gt;
			&lt;div class=&quot;box&quot;&gt;
			&lt;h1&gt;&lt;?php echo $categ_object-&gt;cat_name; ?&gt;&lt;/h1&gt;
			&lt;ul class=&quot;subnavigation&quot;&gt;
			&lt;?php wp_list_categories( 'title_li=&amp;depth=1&amp;child_of=' . (int)$categ_object-&gt;cat_ID ); ?&gt;
			&lt;/ul&gt;
			&lt;/div&gt;
&lt;?php
		}
	}
	// almost the same for page hierarchy.
	if( is_page() ) {
		// here we go...just do the same job
		$page_object = get_post( get_query_var( 'page' ), OBJECT );
		$list_subpages = wp_list_pages( 'title_li=&amp;depth=1&amp;echo=0&amp;child_of=' . (int)$page_object-&gt;ID );
		// wordpress never returns null or empty string. If children, &lt;a&gt; tag will be found, otherwise string is returned.
		preg_match_all( '|&lt;a.*?href=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $list_subpages, $ms );
		if( !$ms[ 1 ] ) {
			if( (int)$page_object-&gt;post_parent &gt; 0 ) {
				$parent_post_name = $wpdb-&gt;get_var( &quot;SELECT post_title FROM $wpdb-&gt;posts WHERE ID=&quot; . (int)$page_object-&gt;post_parent );
?&gt;
				&lt;div class=&quot;box&quot;&gt;
				&lt;h1&gt;&lt;?php echo $parent_post_name; ?&gt;&lt;/h1&gt;
				&lt;ul class=&quot;subnavigation&quot;&gt;
				&lt;?php wp_list_pages( 'title_li=&amp;depth=1&amp;child_of=' . (int)$page_object-&gt;post_parent ); ?&gt;
				&lt;/ul&gt;
				&lt;/div&gt;
&lt;?php
			}
		} else {
?&gt;
				&lt;div class=&quot;box&quot;&gt;
				&lt;h1&gt;&lt;?php echo $page_object-&gt;post_title; ?&gt;&lt;/h1&gt;
				&lt;ul class=&quot;subnavigation&quot;&gt;
				&lt;?php wp_list_pages( 'title_li=&amp;depth=1&amp;child_of=' . (int)$page_object-&gt;ID ); ?&gt;
				&lt;/ul&gt;
				&lt;/div&gt;
&lt;?php
		}
	}
?&gt;
</code>
</pre>
<p>
And this is it; save, and see how it works. You may want to replace style/class name for div in &#8216;navigation.php&#8217; but this should be an easy part.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-build-sequential-navigation-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to display total number of posts</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-display-total-number-of-posts/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-display-total-number-of-posts/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 15:06:53 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[total number]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=178</guid>
		<description><![CDATA[For a case you want to display total number of posts ever published on your blog, here is an easy way to do it. I guess there&#8217;s another method but this one works fine for me just fine. You can say &#8216;Why the hell one would need something like that?&#8217; but just try to Google [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/06/numbers-200x200.jpg" alt="numbers" title="numbers" width="200" height="200" class="alignnone size-thumbnail wp-image-179" />For a case you want to display total number of posts ever published on your blog, here is an easy way to do it. I guess there&#8217;s another method but this one works fine for me just fine. You can say &#8216;Why the hell one would need something like that?&#8217; but just try to Google for the subject of this post and you&#8217;ll see it doesn&#8217;t seem to be so useless. Here it is:</p>
<pre>
<code>
&lt;?php
	$numposts = $wpdb-&gt;get_var( &quot;SELECT COUNT(*) FROM $wpdb-&gt;posts WHERE post_status = 'publish'&quot; );
	echo $numposts;
?&gt;
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-display-total-number-of-posts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to connect WordPress and Flash &#8211; part #1</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-1/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-1/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 12:25:20 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[dynamic content]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[wordpress flash]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=169</guid>
		<description><![CDATA[There&#8217;s quite easy way to connect WordPress and Flash. I&#8217;m talking about pulling dynamic content to Flash, the way you insert swf to your site is just another story. In both cases you&#8217;ll need swfobject.js in order to follow standards-friendly method of embedding Flash. I have never tried to use any of WordPress available plugins, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/06/2connection-done-big-200x200.jpg" alt="2connection-done-big" title="2connection-done-big" width="200" height="200" class="alignnone size-thumbnail wp-image-170" />There&#8217;s quite easy way to connect WordPress and Flash. I&#8217;m talking about pulling dynamic content to Flash, the way you insert <strong>swf</strong> to your site is just another story. In both cases you&#8217;ll need <a href="http://code.google.com/p/swfobject/">swfobject.js</a> in order to follow standards-friendly method of embedding Flash. I have never tried to use any of <a href="http://wordpress.org/extend/plugins/tags/swfobject">WordPress available plugins</a>, somehow I rather include it manually, so at this point I&#8217;m not sure whether it&#8217;ll work with plugin. I guess it should.</p>
<h2>What&#8217;s the purpose of embeded Flash file?</h2>
<p>Are you about to replace standard, HTML navigation with Flashed one? Do you want to make some recent posts slider in sidebar? Maybe some cool tag cloud in footer? Flash can be added whenever you like and do whatever you like. The most important fact about Flash is that it&#8217;s capable to load and process XML and that&#8217;s exactly how we are about to exchange data between WordPress and Flash. Once the data has been loaded into Flash options to display it on some non-standard and interesting way are endless.</p>
<h2>Our task: Create latest Posts list</h2>
<p>For the demonstration purpose we are about to generate the list of latest Posts and send it to embeded Flash file. Each list item will have a title, post date, number of comments, thumbnail image (if any), post category and a link back to post details.</p>
<h2>Preparing backend file</h2>
<p>Let&#8217;s create and save in our theme&#8217;s folder new file called &#8216;flash_recent.php&#8217;. I don&#8217;t know which theme you are using but it doesn&#8217;t matter in deed, it&#8217;ll work with any properly activated WordPress theme. Our new file should be able to connect to database and get required information. In the same time we&#8217;ll output results in standard XML format readable to Flash.</p>
<pre>
<code>

&lt;?php

 // get connected
  require_once( '../../../wp-config.php' );


 // variables
  $xml = &quot;&quot;;
  $num_of_posts_to_display = 5;


 // query posts
  query_posts( 'showposts=' . $num_of_posts_to_display . '&amp;post_type=post&amp;post_status=publish&amp;order=DESC' );


 if( have_posts() ) : while( have_posts() ) : the_post();
  // category ID
  $category = get_the_category();
  // get first thumbnail path
  preg_match_all( '|&lt;img.*?src=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $post-&gt;post_content, $m );
  // format XML
  $xml .= '&lt;item&gt;';
  $xml .= '&lt;title&gt;' . $post-&gt;post_title . '&lt;/title&gt;';
  $xml .= '&lt;postlink&gt;' . get_permalink() . '&lt;/postlink&gt;';
  if( $m[ 1 ] ) $xml .= '&lt;image&gt;' . $m[ 1 ][ 0 ] . '&lt;/image&gt;';
  $xml .= '&lt;category&gt;' . $category[ 0 ]-&gt;cat_name . '&lt;/category&gt;';
  $xml .= '&lt;catid&gt;' . bloginfo( 'home' ) . '?cat=' . $category[ 0 ]-&gt;cat_ID . '&lt;/catid&gt;';
  $xml .= '&lt;date&gt;' . date( 'M j, Y', strtotime( $post-&gt;post_date ) ) . '&lt;/date&gt;';
  $xml .= '&lt;comments&gt;' . $post-&gt;comment_count . '&lt;/comments&gt;';
  $xml .= '&lt;excerpt&gt;' . get_the_excerpt() . '&lt;/excerpt&gt;';
  $xml .= '&lt;/item&gt;';
  endwhile; endif;


 // output results
  echo $xml;


?&gt;

</code>
</pre>
<p>In order to check whether an output is OK you should type in Browser&#8217;s address bar full path to &#8216;flash_recent.php&#8217; file. For eample: <strong>http://yourdomain.com/wp-content/themes/some_themeName/flash_recent.php.</strong></p>
<h2>What next?</h2>
<p>Well, next time we gonna learn how Flash can handle parsed XML. I bet many of you already know how but for the sake of those who doesn&#8217;t &#8211; expect to find an answer in part#2 of this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-connect-wordpress-and-flash-part-1/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Get Category ID by name and vice versa</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/get-category-id-by-name-and-vice-versa/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/get-category-id-by-name-and-vice-versa/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 08:35:14 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[category ID]]></category>
		<category><![CDATA[category name]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=164</guid>
		<description><![CDATA[Have you ever wanted to find out certain category ID by its name or maybe do that in reverse? Maybe I&#8217;m missing something but there&#8217;s no method to achieve that via built-in WordPress functions so here is quick and dirty way of getting category ID by category name and vice versa.
Get cat ID by name


&#60;?php
	$category_slug [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rider.sofarider.com/wp-content/uploads/2009/06/slug_list_view.jpg" rel="shadowbox[post-164];player=img;"><img src="http://rider.sofarider.com/wp-content/uploads/2009/06/slug_list_view-200x200.jpg" alt="slug_list_view" title="slug_list_view" width="200" height="200" class="alignnone size-thumbnail wp-image-166" /></a>Have you ever wanted to find out certain category ID by its name or maybe do that in reverse? Maybe I&#8217;m missing something but there&#8217;s no method to achieve that via built-in WordPress functions so here is quick and dirty way of getting category ID by category name and vice versa.</p>
<h2>Get cat ID by name</h2>
<pre>
<code>
&lt;?php
	$category_slug = &quot;myCategory&quot;; // just an example name/slug
	$category_ID = $wpdb-&gt;get_var( &quot;SELECT term_id FROM $wpdb-&gt;terms WHERE slug = '&quot; . $category_slug . &quot;'&quot; );
?&gt;
</code>
</pre>
<h2>Get cat name by ID</h2>
<pre>
<code>
&lt;?php
	$category_ID = 1; // just an example ID
	$category_name = $wpdb-&gt;get_var( &quot;SELECT name FROM $wpdb-&gt;terms WHERE term_id = &quot; . $category_id );
?&gt;
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/get-category-id-by-name-and-vice-versa/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to extract files attached to Post or Page</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-extract-files-attached-to-post-or-page/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-extract-files-attached-to-post-or-page/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 07:41:52 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[extract]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[post attachment]]></category>
		<category><![CDATA[separate]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=132</guid>
		<description><![CDATA[Sometimes people need to insert download file (or more than just one) either to Post or Page. In that case you will use Add Media button on the top text editor (the very last, fourth icon of an Upload/Insert set). Normally, after you publish Post or Page, file download will become nothing but a standard [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/06/AddAlcoholToExtract.jpg" alt="AddAlcoholToExtract" title="AddAlcoholToExtract" width="450" height="434" class="alignnone size-full wp-image-139" />Sometimes people need to insert download file (or more than just one) either to Post or Page. In that case you will use Add Media button on the top text editor (the very last, fourth icon of an Upload/Insert set). Normally, after you publish Post or Page, file download will become nothing but a standard link within the rest of the text. And this is definitely not what you want, especially when you have something really important to be downloaded. What you want is to be able to position attached file within the content and possibly use appropriate file type icon.<br />
So here is our task:</p>
<ul>
<li>Seek Post or Page content for specific file type(s)</li>
<li>If any found, save to variable for later use</li>
<li>Eliminate download link from original content because we don&#8217;t need duplicates</li>
</ul>
<p>For a case you want to use this method I strongly advise you to either insert files for download on the very top or bottom of Post/Page content. For example, after you are finished with text writing, Add Media below everything. This is how you can keep downloadable files &#8216;out of the context&#8217;. Remember, we are about to trim download link from original content. For a case link is found in the middle of the sentence it may happen part of the sentence marked as a link will be missing.</p>
<pre>
<code>
&lt;?php
	// find attached files - NOT IMAGES!
	$content = get_the_content();
	$attached_files = array(); // files array
	$attached_extensions = array(); // extensions may differ
	$attached_string = array(); // file name or string
	$arr_include = array( 'zip', 'rar', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'ppd', 'txt', 'odf' ); // which file types to watch for
	// matches, browse through all the links first, after that filter matches only
	preg_match_all( '|&lt;a.*?href=[\'&quot;](.*?)[\'&quot;].*?&gt;(.*?)&lt;.*?a&gt;|i', $content, $match_extension );
	// 1 - path to file
	// 2 - file string
	if( $match_extension[ 1 ] ) {
		$c = 0;
		while( $c &lt; count( $match_extension[ 1 ] ) ) {
			$bits = explode( '.', $match_extension[ 1 ][ $c ] );
			if( in_array( $bits[ count( $bits ) - 1 ], $arr_include ) &amp;&amp; strlen( $bits[ count( $bits ) - 1 ] ) &gt; 2 ) {
				array_push( $attached_files, $match_extension[ 1 ][ $c ] );
				array_push( $attached_extensions, $bits[ count( $bits ) - 1 ] );
				array_push( $attached_string, $match_extension[ 2 ][ $c ] );
                             // remove duplicates from the content
				$content = preg_replace( '|&lt;a.*?href=[\'&quot;](' . $match_extension[ 1 ][ $c ] . ')[\'&quot;].*?&gt;(' . $match_extension[ 2 ][ $c ] . ')&lt;.*?a&gt;|i', '', $content );
			}
			$c ++;
		}
		// throw out modified content
		echo $content;
	} else {
		// throw out original content
		the_content();
	}
?&gt;
</code>
</pre>
<h2>How to display files for download</h2>
<p>OK, in case there are downloadable files attached either to Post or Page we have them saved in <strong>$attached_files</strong> array for further usage. Let&#8217;s say we want to make ordered list of files on the bottom of the content. This list will also have a title reading &#8220;Related documents&#8221;.</p>
<pre>
<code>
&lt;?php
	if( count( $attached_files ) &gt; 0 ) {
	// make the list of attached documents
?&gt;
	&lt;div class=&quot;documentList&quot;&gt;
		&lt;h2&gt;Related documents&lt;/h2&gt;
		&lt;ul class=&quot;doclist&quot;&gt;
&lt;?php
		$i = 0;
		$l = count( $attached_files );
		while( $i &lt; $l ) {
			echo '&lt;li class=&quot;' . $attached_extensions[ $i ] . '&quot;&gt;&lt;a href=&quot;' . $attached_files[ $i ] . '&quot;&gt;' . $attached_string[ $i ] . '.' . $attached_extensions[ $i ] . '&lt;/a&gt;&lt;/li&gt;';
			$i++;
		}
?&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&lt;?php
	}
?&gt;
</code>
</pre>
<h2>CSS</h2>
<p>This tutorial would not be complete without using appropriate styles. Remember, we want to be able to display document type icon as well. Note the class assigned to list item! It&#8217;s different for different file type.</p>
<pre>
<code>
.doclist a[href$=&quot;.txt&quot;]		{ background-image: url(images/icon_txt.gif); }
.doclist a[href$=&quot;.doc&quot;],
.doclist a[href$=&quot;.docx&quot;],
.doclist a[href$=&quot;.odf&quot;]		{ background-image: url(images/icon_doc.gif); }
.doclist a[href$=&quot;.xls&quot;],
.doclist a[href$=&quot;.xlsx&quot;]		{ background-image: url(images/icon_xls.gif); }
.doclist a[href$=&quot;.ppd&quot;],
.doclist a[href$=&quot;.ppt&quot;]		{ background-image: url(images/icon_ppt.gif); }
.doclist a[href$=&quot;.pdf&quot;]		{ background-image: url(images/icon_pdf.gif); }
.doclist a[href$=&quot;.zip&quot;]		{ background-image: url(images/icon_zip.gif); }
.doclist a[href$=&quot;.rar&quot;]		{ background-image: url(images/icon_rar.gif); }
</code>
</pre>
<p>As you probably guess previous class declaration will not work for the most stupid Browser ever made on this planet &#8211; IE6. So here is the same, supposed to be saved in separate css file specific for IE6:</p>
<pre>
<code>
.doclist .txt a			{ background-image: url(images/icon_txt.gif); }
.doclist .doc a,
.doclist .docx a,
.doclist .odf a			{ background-image: url(images/icon_doc.gif); }
.doclist .xls a,
.doclist .xlsx a 			{ background-image: url(images/icon_xls.gif); }
.doclist .ppt a,
.doclist .ppd a 			{ background-image: url(images/icon_ppt.gif); }
.doclist .pdf a 			{ background-image: url(images/icon_pdf.gif); }
.doclist .zip a 			{ background-image: url(images/icon_zip.gif); }
.doclist .rar a 			{ background-image: url(images/icon_rar.gif); }
</code>
</pre>
<p>That&#8217;s it. Hopefully someone will find this method useful. I already have and decided to share it with community.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-extract-files-attached-to-post-or-page/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Extend WordPress &#8211; how to spice up sidebar</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/an-idea-behind-the-name-plugger/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/an-idea-behind-the-name-plugger/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 09:01:21 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[how]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[plugger]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=103</guid>
		<description><![CDATA[Not sure whether other WP theme makers will disagree with me but the sidebar content was always &#8211; don&#8217;t get me wrong &#8211; crippled. Especially when we talk about single.php and page.php template files. It&#8217;s true, you can assign different sidebar to each and every template, make it widget ready but there&#8217;s not much left [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/06/plugger-200x200.jpg" alt="plugger" title="plugger" width="200" height="200" class="alignnone size-thumbnail wp-image-104" />Not sure whether other WP theme makers will disagree with me but the sidebar content was always &#8211; don&#8217;t get me wrong &#8211; crippled. Especially when we talk about <strong>single.php</strong> and <strong>page.php</strong> template files. It&#8217;s true, you can assign different sidebar to each and every template, make it widget ready but there&#8217;s not much left than having the very same sidebar content for all of your Posts or all of your Pages. What I am talking about is to have an option to control the sidebar content straight from Post/Page write panel and to be able to even set unique content for a certain Post or Page. To be honest, widgets are quite hard to be made, even for experienced WP programmer and the process takes time. And even if you are skilled enough and damn quick all of your Posts or Pages still have to share the same sidebar.</p>
<h2>Simple, quick and easy solution</h2>
<p>The main question was how to make an easy and acceptable solution even for an average WP theme maker? I guess an average WP theme maker is at least familiar with basic WP functions (methods, properties, objects) and knows how to include external file. On the other side are theme end users and these people are mostly tied to a common article publish routine. According to that fact, adding sidebar content to Post or Page must be as easy as mouse click.</p>
<h2>Code snippets</h2>
<p>After thinking a little bit I&#8217;ve came across quite acceptable solution: code snippets. More precisely, <strong>one snippet</strong> = <strong>one page</strong> which can be included in sidebar whenever is required, straight from Post/Page Write panel. Such &#8216;tiny&#8217; pages should be placed in separate folder and share common prefix in file name because we are about to ease our job for the future. Let&#8217;s now consider the following situation&#8230;<br />
As a theme coder you would like to enable your theme user an easy way to include latest comment in sidebar. You&#8217;ve made a piece of code which may look like this:</p>
<pre>
<code>
&lt;?php
	$cout_comments = 0; // internal counter
	$show_comments = 1; // how many latest comments to display?
	// get all approved comments but in reverse order; the latest one on top
	$comment_array = array_reverse( get_approved_comments( $post-&gt;ID ) );
	// any comments?
	if( $comment_array ) {
		foreach( $comment_array as $comment ) {
			// we need $show_comments comment(s) only
			if( $cout_comments &lt; $show_comments ) {
                     // use predefined styles, widgets use'em as well
?&gt;
			&lt;div class=&quot;box&quot;&gt;
			&lt;h1&gt;Latest comment by &lt;?php comment_author_link(); ?&gt;&lt;/h1&gt;
			&lt;p&gt;
&lt;?php
			// get user gravatar - if any
			$comment_text = get_comment_text();
			$author_email = $comment-&gt;comment_author_email;
			echo get_avatar( $author_email, '80' );
			echo $comment_text;
?&gt;
			&lt;/p&gt;
			&lt;/div&gt;
&lt;?php
			break;
			}
		$cout_comments ++;
		}
	}
?&gt;
</code>
</pre>
<p>Now we need to save our code snippet. As already mentioned before, we&#8217;ll create new folder within our theme folder named &#8216;pluggers&#8217; and save this code snippet as &#8216;plugger_LatestComment.php&#8217;. All other code snippets will be saved in &#8216;pluggers&#8217; folder and use &#8216;plugger_&#8217; in name prefix. However, if you don&#8217;t like to use phrase &#8216;plugger&#8217; &#8211; go ahead and make up your own. In this tutorial we&#8217;ll keep using &#8216;plugger&#8217;.</p>
<h2>Custom Write panel</h2>
<p>Let&#8217;s now build user-friendly interface in Admin panel which will be used to insert our code whenever is required. This part is based on great tutorial published by <a href="http://wefunction.com/2008/10/tutorial-creating-custom-write-panels-in-wordpress/">WeFunction</a> and I strongly recommend to read it for better understanding of what we are about to do here. The following code must be included in <strong>functions.php</strong>, that&#8217;s how we make it available to Post or Page write panel.</p>
<pre>
<code>
&lt;?php
$array_values_post_page = array();
function sidebar_meta_boxes() {
	global $post, $array_values_post_page;
	// anything already writen in Custom Field?
	if( get_post_meta( $post-&gt;ID, 'plugger_value', false ) ) {
		$plugger_values_post_page = implode( &quot;,&quot;, get_post_meta( $post-&gt;ID, 'plugger_value', false ) );
	} else $plugger_values_post_page = &quot;&quot;;
	echo '&lt;p style=&quot;padding: 5px 0;&quot;&gt;&lt;em&gt;Tick the checkbox for each Plugger you want to be visible in sidebar, next to this article/page. Add sorting number to change the appearance order.&lt;/em&gt;&lt;/p&gt;&lt;h4&gt;List of available Pluggers:&lt;/h4&gt;&lt;hr style=&quot;border: 1px dashed #F1F1F1; height: 1px;&quot; /&gt;';
	echo &quot;&lt;input type='hidden' name='plugger_value' id='plugger_value' value='&quot; . $plugger_values_post_page . &quot;' size='33'&gt;&lt;/input&gt;&quot;;
	if( $plugger_values_post_page != &quot;&quot; ) {
		$array_values_post_page = explode( &quot;,&quot;, $plugger_values_post_page );
	}
	// get all available Pluggers from a certain folder
	$path = TEMPLATEPATH . &quot;/pluggers&quot;;
	$dir = opendir( $path );
	while( ( $plugger_file = readdir( $dir ) ) !== false ) {
	if( $plugger_file != &quot;.&quot; &amp;&amp; $plugger_file != &quot;..&quot; ) {
		$data_aray = explode( &quot;_&quot;, $plugger_file );
		if( $data_aray[ 0 ] == &quot;plugger&quot; ) {
			$checked = &quot;&quot;;
			$suffix = explode( &quot;.&quot;, $data_aray[ 1 ] );
			$val = &quot;&quot;;
			$in_position = key( preg_grep( &quot;/{$suffix[ 0 ]}/i&quot;, $array_values_post_page ) );
			// pluggers are sorted by numbers, sorting position writen after plugger name like pluggerName:n
			if( strlen( $in_position ) &gt; 0 ) {
				$in_p_arr = explode( &quot;:&quot;, $array_values_post_page[ $in_position ] );
				$val = $in_p_arr[ 1 ];
				$checked = ' checked=&quot;checked&quot;';
			}
			echo &quot;&lt;div style='width: 266px; clear: both; overflow: hidden; padding: 5px 0; border-bottom: 1px solid #F1F1F1;'&gt;&quot;;
			echo &quot;&lt;div style='float: left; display: inline; width: 170px; padding-top: 8px;'&gt;&quot;;
			echo &quot;&lt;input style='margin-right: 5px;' type='checkbox' id='&quot; . $suffix[ 0 ] . &quot;' name='plugger_names' value='&quot; . $suffix[ 0 ] . &quot;' &quot; . $checked . &quot; onchange='addPostPagePluggers()' /&gt;&quot;;
			echo &quot;&lt;label for='&quot; . $suffix[ 0 ] . &quot;'&gt;&quot; . $suffix[ 0 ] . &quot;&lt;/label&gt;&quot;;
			echo &quot;&lt;/div&gt;&quot;;
			echo &quot;&lt;div style='float: left; display: inline; width: 95px;'&gt;&quot;;
			echo &quot;&lt;input type='text' style='margin-right: 5px; width: 26px;' name='sort_&quot; . $suffix[ 0 ] . &quot;' id='sort_&quot; . $suffix[ 0 ] . &quot;' value='&quot; . $val . &quot;' size='2' onchange='addPostPagePluggers()'&gt;&lt;/input&gt;&quot;;
			echo &quot;&lt;label for='sort_&quot; . $suffix[ 0 ] . &quot;'&gt;sort num.&lt;/label&gt;&quot;;
			echo &quot;&lt;/div&gt;&quot;;
			echo &quot;&lt;/div&gt;&quot;;
		}
	}
	}
	closedir( $dir );
?&gt;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
function addPostPagePluggers() {
	// watch for checkbox activity and sort out elements for the frontend
	var val = &quot;&quot;;
	var old = document.getElementById( &quot;post&quot; ).plugger_value; // hidden field which holds an array of name-value pairs
	var cbs = document.getElementById( &quot;post&quot; ).plugger_names; // an array (names) of available pluggers represented via check boxes
	for( var n = 0; n &lt; cbs.length; n ++ ) {
		if( cbs[ n ].checked ) {
		var sort_field = eval( &quot;document.getElementById( 'post' ).sort_&quot; + cbs[ n ].id );
		var sort_num = parseInt( sort_field.value );
		if( isNaN( sort_num ) ) sort_field.value = n + 1;
			val += cbs[ n ].value + &quot;:&quot; + sort_field.value + &quot;,&quot;;
		} else {
			var sort_field = eval( &quot;document.getElementById( 'post' ).sort_&quot; + cbs[ n ].id );
			sort_field.value = &quot;&quot;;
		}
	}
	var temp = val.split( &quot;,&quot; );
	temp.pop();
	// sort by :n
	temp.sort( function compareStrnum( a, b ) { return a.replace( /[^.0-9]/g, &quot;&quot; ) - b.replace( /[^.0-9]/g, &quot;&quot; ) } );
	old.value = temp.toString();
}
&lt;/script&gt;
&lt;?php
}
// save settings on Admin level routine
function create_meta_box() {
	if ( function_exists('add_meta_box') ) {
		add_meta_box( 'sidebar_meta_boxes', 'Pluggers to include in Page Sidebar', 'sidebar_meta_boxes', 'page', 'side', 'high' );
		add_meta_box( 'sidebar_meta_boxes', 'Pluggers to include in Post Sidebar', 'sidebar_meta_boxes', 'post', 'side', 'high' );
	}
}

function save_postdata( $post_id ) {
	global $post, $array_values_post_page;
	if ( 'page' == $_POST[ 'post_type' ] ) {
		if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id;
	} else {
		if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
	}
	$data = $_POST[ 'plugger_value' ];
	if( get_post_meta( $post_id, 'plugger_value' ) == &quot;&quot; ) {
		add_post_meta( $post_id, 'plugger_value', $data, true );
	} elseif( $data != get_post_meta( $post_id, 'plugger_value', true ) ) {
		update_post_meta( $post_id, 'plugger_value', $data );
	} elseif( $data == &quot;&quot; ) {
		delete_post_meta( $post_id, 'plugger_value', get_post_meta( $post_id, 'plugger_value', true ) );
	}
}

add_action( 'admin_menu', 'create_meta_box' );
add_action( 'save_post', 'save_postdata' );
?&gt;
</code>
</pre>
<p>What this code is supposed to do? First, it&#8217;ll seek for all files in &#8216;pluggers&#8217; folder whose name starts with &#8216;plugger_&#8217;. In the same time it checks whether a current Post or Page already has any of available Pluggers aassigned to it. Settings are kept in Custom Field of a current Post or Page so every time you are about to edit one of those the list of available Pluggers and already selected ones is properly populated.<br />
Javascript watches for all the changes made to the list and sorts it out immediately. That&#8217;s how we can get all of selected Pluggers properly sorted in frontend. The last two functions are used to insert our meta box to Post/Page sidebar write panel and save settings to database.</p>
<h2>Getting values in frontend</h2>
<p>So far we&#8217;ve created Plugger unit called &#8216;plugger_LatestComment.php&#8217; and meta box which will be displayed in Post/Page write panel (sidebar). Now we just have to get certain Custom Field value out of the Post/Page and display it in frontend. For a case you didn&#8217;t notice in <strong>save_postdata()</strong> function is the name of our Custom Field <strong>plugger_value</strong> which is either supposed to be created, updated or deleted &#8211; according to meta box selected value(s). Here is the piece of code used to pull required meta values out of the Post or Page:</p>
<pre>
<code>
&lt;?php 
	$post_data = get_post_custom_keys( $post-&gt;ID );
	foreach( $post_data as $postKey ) {
	// remove orphans
	$value_trimmed = trim( $postKey );
	if ( '_' == $value_trimmed{0} ) continue;
		// what we have here?
		$postKey_data[ $postKey ] = get_post_meta( $post-&gt;ID, $postKey );
		// check for checkbox values
		if( $postKey == &quot;plugger_value&quot; ) {
			// compile file name
			$filename_arr = explode( &quot;,&quot;, $postKey_data[ $postKey ][ 0 ] );
			$c = 0;
			while( $c &lt; count( $filename_arr ) ) {
				$file_to_include = explode( &quot;:&quot;, $filename_arr[ $c ] );
				// include in sidebar
				include( TEMPLATEPATH . &quot;/pluggers/plugger_&quot; . $file_to_include[ 0 ] . &quot;.php&quot; );
				$c ++;
			}
		}
	}
?&gt;
</code>
</pre>
<p>For a case you want to display Pluggers above other widgets in sidebar &#8211; paste the code on the top of <strong>sidebar-single.php</strong> or <strong>sidebar-page.php</strong>. Otherwise paste it below widget reserved area &#8211; if any.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/an-idea-behind-the-name-plugger/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
