<?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>nooshu &#187; code Archives </title>
	<atom:link href="http://nooshu.com/tag/code/feed" rel="self" type="application/rss+xml" />
	<link>http://nooshu.com</link>
	<description>Kneeling on the shoulders of giants</description>
	<lastBuildDate>Sun, 15 Apr 2012 13:42:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>A little bit of MicroJS</title>
		<link>http://nooshu.com/a-little-bit-of-microjs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-little-bit-of-microjs</link>
		<comments>http://nooshu.com/a-little-bit-of-microjs#comments</comments>
		<pubDate>Sun, 29 May 2011 18:12:10 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vanilla JavaScript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[small]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1732</guid>
		<description><![CDATA[For some projects you may not need a fully featured JavaScript library. But what are the alternatives?]]></description>
			<content:encoded><![CDATA[<p>Recently there was a flurry of talk around a little something called MicroJS, mainly thanks to a website of the same name created by <a href="http://mir.aculo.us/">Thomas Fuchs</a>, author of the <a href="http://script.aculo.us/">script.aculo.us</a> user interface library. I&#8217;m not sure if Thomas coined the term &#8220;MicroJS&#8221; or if it&#8217;s been in use for a while, but it describes the micro-framework methodology perfectly. So what is a micro-framework? The best way to answer that is to first ask what is a JavaScript framework?</p>
<p>JavaScript frameworks have been around since around 2005 (looking at the Prototype and jQuery history); their purpose is to allow developers to easily add interactivity to a page by creating a JavaScript abstraction layer to build from. The library takes care of any cross browser issues and quirks, allowing developers to focus on the &#8220;cool&#8221; stuff, building websites. As a developer I can&#8217;t thank all the library authors enough; without them my working life would be so much more stressful (and my hair would be even grayer than it is now!).</p>
<p>Once you know what a JavaScript framework is, it doesn&#8217;t take a genius to guess what a micro-framework is. Where as a full framework will have many tools (methods) a developer can use, a micro-framework only focuses on a very specific set of functions. I like the knife analogy: a full-framework like Dojo would be a Swiss Army knife where as a micro-framework could be considered a small pen knife. So which do you use in a project? This completely depends on the project in hand. I&#8217;ve put together a small list of pros and cons for each (let me know if you have any others):</p>
<h3>Full Framework</h3>
<ul>
<li><strong>Pros</strong></li>
<li>Extensive set of features to cater for most eventualities.</li>
<li>Consistent API across features.</li>
<li>Large user base with lots of community support.</li>
<li>Huge number of working examples available.</li>
<li>Many developers to fix bugs and add additional functionality.</li>
<li>Single point of reference of documentation.</li>
</ul>
<ul>
<li><strong>Cons</strong></li>
<li>Large code base could be very daunting to new users.</li>
<li>Large page footprint.</li>
<li>Many features of the library may not be needed.</li>
</ul>
<h3>Micro-Framework</h3>
<ul>
<li><strong>Pros</strong></li>
<li>Small page weight, usually less than 5K.</li>
<li>Small set of features so very quick to pick up and use.</li>
<li>Main focus on a very specific set of functionality.</li>
<li>No feature creep or excess code.</li>
<li>Use the right tool for the right job.</li>
</ul>
<ul>
<li><strong>Cons</strong></li>
<li>Small number of developers, bugs and issues may take a while to be fixed.</li>
<li>Development of the framework may stop completely.</li>
<li>May be very little support from the author and the community.</li>
<li>Fellow developers in your team may not be familiar with the framework.</li>
<li>Mixing micro-frameworks could conflict if badly coded.</li>
<li>Multiple frameworks could mean multiple HTTP requests.</li>
<li>Multiple points of reference for API docs.</li>
<li>Multiple frameworks could lead to an overlap in functionality.</li>
</ul>
<p>Many of the cons for micro-frameworks stem from using more than one at a time, but if you only plan on using one then they can be ignored.</p>
<p>Micro-frameworks caught my eye recently due to a couple of small projects I&#8217;d been working on. The projects all used vanilla JavaScript as there was no need for a helper library. I later realised I needed to attach a few events and manipulate the DOM but I wanted to avoid including jQuery in the project as I only needed a small fraction of its functionality. Luckily the MicroJS website came to the rescue.</p>
<p>The examples below are taken from <a href="https://github.com/ded/qwery">Query</a>, <a href="https://github.com/ded/bonzo">Bonzo</a>, <a href="https://github.com/kbjr/Events.js">Events.js</a> and <a href="https://github.com/fat/bean">Bean</a>. As you can see the usage for each is pretty self-explanatory with lots more functionality is available from each library&#8217;s website. If you&#8217;re a jQuery user the syntax will look <a href="http://www.dustindiaz.com/qwery">very familiar</a>.</p>
<p><strong>CSS selector and DOM utility</strong></p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">/*<br />
Query - Dustin Diaz<br />
https://github.com/ded/qwery<br />
CSS selector engine<br />
*/</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.myclass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myid .myclass div a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a, div, strong&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
Query Paired with Bonzo - Dustin Diaz<br />
https://github.com/ded/bonzo<br />
DOM utility<br />
*/</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myid&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.myclass&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myid .myclass div a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;anchorClass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
query<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a, div, strong&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>Events</strong></p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">/*<br />
Events.js - James Brumond<br />
https://github.com/kbjr/Events.js<br />
Event handler library<br />
*/</span><br />
Events.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Page loaded, do something</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//Invoke the page load event</span><br />
Events.<span style="color: #660066;">invoke</span><span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//Mouse click event</span><br />
Events.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>selectedElements<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Mouse has been clicked</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//Very handy keystroke event</span><br />
Events.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>document<span style="color: #339933;">,</span> <span style="color: #3366CC;">'keystroke.Ctrl+Shift+Alt+S'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; saveMySlices<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
Bean - Dustin Diaz<br />
https://github.com/fat/bean<br />
Event handler library<br />
*/</span><br />
bean.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>selectedElements<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Mouse has been clicked</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//DOM has loaded</span><br />
bean.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>document<span style="color: #339933;">,</span> <span style="color: #3366CC;">'DOMContentLoaded'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Page loaded, do something</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//Invoke an event on an element</span><br />
bean.<span style="color: #660066;">fire</span><span style="color: #009900;">&#40;</span>selectedElement<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//Remove the event from an element</span><br />
bean.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span>selectedElement<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>I&#8217;ll be trying out a few more of these micro-frameworks for my personal projects in the future as the ability to select only the functionality you need really appeals to me. Are there any other micro-frameworks you&#8217;ve used that you&#8217;d recommend? Leave me a comment and I&#8217;ll check them out.</p>
<p><strong>Update</strong>: It just so happens that a handy library website has emerged inspired by the MicroJS website called <a href="http://www.everyjs.com/">EveryJS</a>. The website lists all library&#8217;s rather than just micro versions. Not all are listed but I&#8217;m sure they will be added soon so it&#8217;s one to keep your eye on.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/a-little-bit-of-microjs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Page not found with custom post types</title>
		<link>http://nooshu.com/page-not-found-with-custom-post-types?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=page-not-found-with-custom-post-types</link>
		<comments>http://nooshu.com/page-not-found-with-custom-post-types#comments</comments>
		<pubDate>Wed, 20 Oct 2010 07:51:50 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1435</guid>
		<description><![CDATA[I hope other people find this fix useful, I wish I'd known about it a few hours earlier...]]></description>
			<content:encoded><![CDATA[<p>Just a quick post on a very frustrating problem I was having with WordPress and the new <a href="http://codex.wordpress.org/Custom_Post_Types">custom post types</a> introduced in version 3.0. Everything was rolling along smoothly until it came to actually viewing one of the custom posts&#8230; 404 error. Weird, maybe a .htaccess issue&#8230; nope that&#8217;s all good, spelling error.. nope. Long story short, this tinkering went on for a good couple of hours and the problem wouldn&#8217;t go away&#8230;. cry! I tried everything I could think of but nothing helped. I could view the post pages with permalinks turned off, but it failed with them turned on.</p>
<p>After hours of frustration I stumbled upon a similar forum post with the answer:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">flush_rewrite_rules<span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Hours of frustration over such a simple fix. Sods law I guess. Add this code to the function you use to register your custom post type like so (usually in your themes functions.php):</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> post_type_myposttype<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$labels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Labels here */</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; register_post_type<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'myposttype'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'labels'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$labels</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'singular_label'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My Post Type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* More settings etc */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'custom-post-slug'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'supports'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumbnail'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'excerpt'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'custom-fields'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* IMPORTIONT: Remember this line! */</span><br />
&nbsp; &nbsp; flush_rewrite_rules<span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">/* Please read &quot;Update 2&quot; before adding this line */</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">//Initialise custom post type</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_type_myposttype'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>No more 404 errors! Huzzah! <strong>One last tip</strong>: make sure you turn off any caching plug-ins (DB-Cache reloaded, Hypercache etc) before you start redeveloping your WordPress blog. Yes I made that mistake too! Yesterday evening is one I wish to forget&#8230;</p>
<p><strong>Update</strong>: If you are adding custom taxonomies to your post types you may need to add the flush rewrite rules to the function when you initialise them:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> create_custom_taxonomies<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'taxonomy1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'posttypename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Taxonomy1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'taxonomy2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'posttypename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Taxonomy2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; flush_rewrite_rules<span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">/* Please read &quot;Update 2&quot; before adding this line */</span><br />
<span style="color: #009900;">&#125;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'create_custom_taxonomies'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>Update 2</strong>: Adding flush_rewrite_rules in the places mentioned above will force a flush for every page load. This is bad! For a better solution see Kens comment below. </p>
<p>Alternatively you could add the flush_rewrite_rules where suggested and reload your page; this will flush the rewrite rules and fix the 404 errors. Remember to <strong>remove or comment out the flush_rewrite_rules</strong> line after as it&#8217;s no longer needed! Thanks Ken for this update.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/page-not-found-with-custom-post-types/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Goodbye Aptana, hello Komodo Edit</title>
		<link>http://nooshu.com/goodbye-aptana-hello-komodo-edit?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=goodbye-aptana-hello-komodo-edit</link>
		<comments>http://nooshu.com/goodbye-aptana-hello-komodo-edit#comments</comments>
		<pubDate>Fri, 01 Oct 2010 17:23:34 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1399</guid>
		<description><![CDATA[I've finally taken the plunge and I'm ditching Aptana IDE. I've been wanting to for a while but haven't found the right alternative.. until now.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://www.aptana.com/">Aptana IDE</a> for a good few years now, before that I used <a href="http://www.eclipse.org/">Eclipse IDE</a>. As Aptana is based on Eclipse, moving between them was very easy with only minor differences between the two. Unfortunately I find the Eclipse platform as a whole very bloated. As a Web Developer there are just so many functions and features I&#8217;m never going to use. The bloat kills the IDEs startup time and after a while this becomes very annoying. So I decided it&#8217;s time to find an alternative.</p>
<p>Talking to a fellow developer recently he recommended <a href="http://www.activestate.com/komodo-edit">Komodo Edit</a> (free), which is essentially a cut down version of Komodo IDE (not free). The list of features it supports is huge, way to many to list in this blog post but here are the ones that really caught my eye:</p>
<ul>
<li>Supports multiple client-side and server-side technologies (HTML, CSS, JavaScript, PHP, Python)</li>
<li>No fuss auto-completion on many languages (this was sometimes an issue for me in Aptana).</li>
<li>Supports various JavaScript libraries for auto-completion (enabled via preferences).</li>
<li>Support for code snippets at the click of a button; helps cut down on some of the monkey work.</li>
<li>XPI extensions available. What makes Firefox so great is it&#8217;s many extensions. This is also possible in Komodo.</li>
<li>There&#8217;s an extension for <a href="http://code.google.com/p/zen-coding/">Zen coding</a> available (yay!).</li>
</ul>
<div id="attachment_1404" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/10/komodo-edit-interface.gif"><img src="http://nooshu.com/wp-content/uploads/2010/10/komodo-edit-interface-518x428.gif" alt="The Komodo Edit interface" title="komodo-edit-interface" width="518" height="428" class="size-medium wp-image-1404" /></a><p class="wp-caption-text">Komodo Edit Interface: simple but functional.</p></div>
<p>It hasn&#8217;t been all plain sailing though, there are a few features that I miss from Aptana:</p>
<ul>
<li>Integration with Subversion (I&#8217;m guessing this is a Komodo IDE feature).</li>
<li>JSlint for the JavaScript, but I have seen an extension available so this may be possible.</li>
<li>Aptanas auto-complete feature for CSS showed what browsers were supported by the typed property, which was quite handy at times.</li>
<li>Aptana used to add the trailing &#8220;;&#8221; in CSS to properties (it&#8217;s amazing how much you miss this feature when it isn&#8217;t there!).</li>
</ul>
<p>These aren&#8217;t major issues, certainly not big enough to keep me using Aptana. Hopefully as the Komodo community grows more extensions and (useful) features will be developed. As long it stays quick to load and use, I&#8217;ll be happy!</p>
<p><strong>Update:</strong> After using Komodo for a few more days I&#8217;ve noticed a couple more little bugs / annoyances:</p>
<ul>
<li>Auto-completing a paragraph tag automatically inserts &#8220;class=&#8217;classname&#8217;&#8221;, not quite sure why I&#8217;d need a class for every paragraph. Maybe there&#8217;s a preference for this?</li>
<li>When you paste in a long line of text it seems to &#8220;drop off&#8221; the end of the page and isn&#8217;t recognised by the horizontal scrollbar. The only way to solve this is to use the right scrollbar arrow. Very weird!</li>
<li>When indenting multiple lines of code using the &#8216;Tab&#8217; key it seems to fail and only indent the line directly below the selected text. Another strange one.</li>
</ul>
<p>There&#8217;s a beta release of version 6 out available on the website, maybe they have been reported and fixed. I&#8217;ll install it and see what happens. Fingers crossed!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/goodbye-aptana-hello-komodo-edit/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nooshu.com now with added HTML5 goodness</title>
		<link>http://nooshu.com/nooshu-com-now-with-added-html5-goodness?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nooshu-com-now-with-added-html5-goodness</link>
		<comments>http://nooshu.com/nooshu-com-now-with-added-html5-goodness#comments</comments>
		<pubDate>Sat, 17 Jul 2010 14:05:50 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1279</guid>
		<description><![CDATA[Finally got round to HTML5ing my Wordpress theme. Lots to learn with the (ongoing) HTML5 specifications.]]></description>
			<content:encoded><![CDATA[<p>So I finally pulled my finger out and took the HTML5 plunge over the past day or so; the Nooshu WordPress theme now has a sprinkling of HTML5. Mmmm I have that warm fuzzy feeling of completeness! In all honesty it&#8217;s been an easy way to learn about the new <a href="http://dev.w3.org/html5/spec/Overview.html">HTML5 specifications</a> (although they aren&#8217;t complete and won&#8217;t become a W3C recommendation until 2022&#8230; no that isn&#8217;t a typo!).</p>
<p>HTML5 has added a host of new tags which have much more semantic meaning. So instead of using &#8216;divs&#8217; to section off areas of your page layout, you can now use:</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- Some of the new HTML5 Tags --&gt;</span><br />
<span style="color: #009900;">&lt;header&gt;&lt;<span style="color: #66cc66;">/</span>header&gt;</span><br />
<span style="color: #009900;">&lt;footer&gt;&lt;<span style="color: #66cc66;">/</span>footer&gt;</span><br />
<span style="color: #009900;">&lt;article&gt;&lt;<span style="color: #66cc66;">/</span>article&gt;</span><br />
<span style="color: #009900;">&lt;section&gt;&lt;<span style="color: #66cc66;">/</span>section&gt;</span><br />
<span style="color: #009900;">&lt;nav&gt;&lt;<span style="color: #66cc66;">/</span>nav&gt;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s certainly a welcome addition to the modern web. My favourite part of HTML5 has to be the doctype (other than the canvas element):</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- No more --&gt;</span><br />
<span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span><br />
<br />
<span style="color: #808080; font-style: italic;">&lt;!-- Much better! --&gt;</span><br />
<span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span></div></td></tr></tbody></table></div>
<p>Look how simple it is! No more copy / paste from a previous project for this doctype.</p>
<p>My main concern when converting the theme to HTML5 was how it would work in IE; as IE8 supports parts of HTML5 but IE6 and IE7 not at all. When IE comes across a tag it doesn&#8217;t recognise it just ignores it. Since the tags aren&#8217;t recognised you won&#8217;t be able to style your lovely new HTML5 template in IE6 &#038; IE7. Lucky you can patch this missing functionality using JavaScript. Remy Sharp has created a script called <a href="http://remysharp.com/2009/01/07/html5-enabling-script/">html5shim</a>, that adds the missing tags to IE. Just add the following code to your header and you will now be able to style your HTML5 tags:</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!--[if lt IE 9]&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &lt;script src=&quot;http://html5shim.googlecode.com/svn/trunk/html5.js&quot;&gt;&lt;/script&gt;</span><br />
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span></div></td></tr></tbody></table></div>
<p>The script must be in the header and must fire before the DOM is created. The script simply creates all the new HTML5 elements using the document method &#8216;createElement&#8217;, you don&#8217;t even need to attach the created elements to the DOM! Now IE will recognise the tags and you can get on with your page styling. Yay!</p>
<p>Those who use WordPress 3.0 may have noticed that the default Kubric theme is no more and it&#8217;s been replaced with a new theme called twenty ten. The theme uses the HTML5 doctype but it doesn&#8217;t use any of the new tags. I guess because of the IE issues. Maybe this will be changed in future releases.</p>
<p>The Nooshu theme is still a work in progress, and I&#8217;ll modify areas as I learn more about the new HTML5 features. Here are a selection of links that I found incredibly useful while working on the theme:</p>
<ul>
<li><strong><a href="http://diveintohtml5.org/">Dive into HTML5</a></strong>: Read through this article and you will be well on your way to learning HTML5. It delves into the history of HTML and progresses forward right up to implementing the new specifications.</li>
<li><strong><a href="http://html5doctor.com/">HTML5 Doctor</a></strong>: Looking for HTML5 related news or need some clarification of a new tag? Look no further than HTML5 Doctor. Lots of articles available for you to read and there&#8217;s even the option to ask a question if you don&#8217;t find the answers you are looking for.</li>
<li><strong><a href="http://gsnedders.html5.org/outliner/">HTML 5 Outliner</a></strong>: So you&#8217;ve created your shiny new HTML5 template; why not check it with the outliner to see if it makes sense to a user / search engine.</li>
<li><strong><a href="http://validator.w3.org/">W3C Markup Validator</a></strong>: It&#8217;s been a while since I&#8217;ve used a validator since I have one <a href="https://addons.mozilla.org/firefox/addon/249">built into Firefox</a>, but the W3C validator was very handy for pointing out attributes and tags that are no longer supported in the specifications. It also gives you a quick benchmark to aim at.</li>
</ul>
<p>If you have any other useful HTML5 tips and links let me know below.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/nooshu-com-now-with-added-html5-goodness/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aptana on Steroids using Zen Coding</title>
		<link>http://nooshu.com/aptana-on-steroids-using-zen-coding?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=aptana-on-steroids-using-zen-coding</link>
		<comments>http://nooshu.com/aptana-on-steroids-using-zen-coding#comments</comments>
		<pubDate>Tue, 04 May 2010 18:11:58 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[aptana]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[front-end]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1095</guid>
		<description><![CDATA[Zen Coding really is an incredibly simple idea, use CSS selectors to write HTML. It sounds like a chicken egg argument, but it really works. ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve mentioned before in previous articles that <a href="http://www.aptana.org/">Aptana</a> is my IDE of choice; one which I&#8217;ve been using for a few years. I only use a handful of the many features available in Aptana, all of which are also available in other editors (<a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> being one), but I&#8217;ve got so used to the way it works I&#8217;m sticking with it for the moment.</p>
<p>One of Aptana&#8217;s helpful features is the ability to generate code using the easy to access menu bar at the top of the code window (see image):</p>
<div id="attachment_1098" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/05/aptana-code-feature.gif"><img src="http://nooshu.com/wp-content/uploads/2010/05/aptana-code-feature-518x112.gif" alt="Aptana has a host of code helpers available" title="aptana-code-feature" width="518" height="112" class="size-medium wp-image-1098" /></a><p class="wp-caption-text">Generate and wrap code at the touch of a button</p></div>
<p>A superb feature it must be said, but it is totally eclipsed when you start using the <a href="http://code.google.com/p/zen-coding/">Zen Coding JavaScript Library</a>. Zen Coding, written by Sergey Chikuyonok isn&#8217;t a JavaScript Library in the traditional sense, it isn&#8217;t uploaded and linked to in your web page; it&#8217;s installed as a plug-in for your selected <a href="http://code.google.com/p/zen-coding/downloads/list">text editor</a>. As you can see from <a href="http://code.google.com/p/zen-coding/downloads/list">the list</a> there are many versions available, so you aren&#8217;t restricted to only Aptana.</p>
<p>Let me explain what it does first, then I&#8217;ll show you how to install it (for Aptana). As a Front End Web Developer you will often find you&#8217;re writing out the same blocks of code again and again. You can just copy / paste then modify, but even that&#8217;s quite slow and tedious. Zen Coding uses a technology that you will be very familiar with: CSS selectors. It may seem confusing at first, but once you see it in action it makes perfect sense. Here are a few  code examples I use all the time:</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!--</span><br />
<span style="color: #808080; font-style: italic;">Entering</span><br />
<span style="color: #808080; font-style: italic;">ul#mainNav&gt;li*5&gt;a</span><br />
<span style="color: #808080; font-style: italic;">generates the list below</span><br />
<span style="color: #808080; font-style: italic;">--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mainNav&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Using simple CSS selectors we&#8217;ve been able to quickly generate an unordered list that can be used for example, as a page navigation. You can even use more advanced selectors like siblings and abbreviated groups to generate more advanced HTML:</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!--</span><br />
<span style="color: #808080; font-style: italic;">Entering</span><br />
<span style="color: #808080; font-style: italic;">div#wrapper&gt;div#header+div#content+div#footer</span><br />
<span style="color: #808080; font-style: italic;">generates this div set below</span><br />
<span style="color: #808080; font-style: italic;">--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;footer&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<br />
<span style="color: #808080; font-style: italic;">&lt;!--</span><br />
<span style="color: #808080; font-style: italic;">Or a more advanced example</span><br />
<span style="color: #808080; font-style: italic;">div#content&gt;(div.primary-section&gt;h2.header+p+ul&gt;li*5)+(div.secondary-section&gt;h3+p)</span><br />
<span style="color: #808080; font-style: italic;">generates the sections below</span><br />
<span style="color: #808080; font-style: italic;">--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;primary-section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;secondary-section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p>It may take a little while to get into the routine, it&#8217;s all to easy to slip back into typing the code by hand; but once you do you can build the basic mark-up of a page in a matter of minutes. </p>
<p>There&#8217;s a very informative article on <a href="http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/">Smashing Magazine</a> from last year which you may find useful if you plan on investigating Zen Coding further; I highly recommend adding it to your &#8220;toread&#8221; list. There are so many more functions available that I haven&#8217;t even touched on in this article, you will be amazed.</p>
<p>Now that you&#8217;ve seen Zen Coding in action you may be wondering how you install it for use with Aptana. Well luckily it&#8217;s dead simple. First create a &#8216;new project&#8217; in Aptana, call it whatever you like e.g. &#8216;Zen Coding&#8217;:</p>
<p><a href="http://nooshu.com/wp-content/uploads/2010/05/aptana-setup.gif"><img src="http://nooshu.com/wp-content/uploads/2010/05/aptana-setup-518x254.gif" alt="Simple to setup Aptana with Zen Coding" title="aptana-setup" width="518" height="254" class="alignnone size-medium wp-image-1102" /></a></p>
<p>Within the new project create a scripts directory and copy the Zen Coding JavaScript into into the directory. That&#8217;s it you&#8217;re done! Restart Aptana and start using Zen Coding. Once you&#8217;ve typed in a string of CSS selectors you wish to convert to HTML, hit CTRL + E (Expand Abbreviation) and it will do the rest for you. One thing to note, you must keep the new project you&#8217;ve just created open at all times, else Aptana won&#8217;t be able to access the scripts.</p>
<p>You can customise the key you use expand an abbreviation by editing the &#8220;Key&#8221; value in &#8220;Expand Abbreviation.js&#8221;. For more information on available keycodes see the <a href="http://docs.aptana.com/docs/index.php/Eclipse_Monkey_scripting_with_Ruby#Adding_metadata_to_your_script">Aptana documentation here</a>.</p>
<p>Hopefully you find Zen Coding useful, it&#8217;s certainly changed the way I code on a day to day basis.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/aptana-on-steroids-using-zen-coding/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeColorer Auto Expanding Code</title>
		<link>http://nooshu.com/codecolorer-auto-expanding-code?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=codecolorer-auto-expanding-code</link>
		<comments>http://nooshu.com/codecolorer-auto-expanding-code#comments</comments>
		<pubDate>Fri, 16 Apr 2010 15:26:35 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=976</guid>
		<description><![CDATA[Added a little feature to the CodeColourer Wordpress plug-in on my website that I'd thought I'd share with people.]]></description>
			<content:encoded><![CDATA[<p>Just quick post on a small feature I&#8217;ve just added to the site which I thought I&#8217;d share. It&#8217;s a slight addition to the <a href="http://wordpress.org/extend/plugins/codecolorer/">CodeColourer plug-in</a> for WordPress. CodeColourer formats and colourises code blocks in your blog posts for better readability. It comes with several different styles built in, or you can customise it using your own CSS file.</p>
<p>A feature that I saw on another site (although I can&#8217;t remember which) was when a user rolled over a code box it would expand to fit the code, allowing the user to see everything. Cool little addition, so I decided to create my own using jQuery. I&#8217;ve taken some of the code from the plug-in and pasted it below so you can see it in action:</p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.codecolorer-container&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> $code <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.codecolorer-container&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> $this <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Animation decision object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> decisionObject <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Original width / height of the displayed code</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> originalWidth <span style="color: #339933;">=</span> $this.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> originalHeight <span style="color: #339933;">=</span> $this.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Width / height of hidden portion of code</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> mainWidth <span style="color: #339933;">=</span> $this.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.codecolorer&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> mainHeight <span style="color: #339933;">=</span> $this.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.codecolorer&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> lineWidth <span style="color: #339933;">=</span> $this.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.line-numbers&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Only attach events if needed (ie has scroll bars)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>mainWidth <span style="color: #339933;">+</span> lineWidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> originalWidth <span style="color: #339933;">||</span> mainHeight <span style="color: #339933;">&gt;</span> originalHeight<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/* and so on...... */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Since this action is fired on hover, I didn&#8217;t want the code boxes expanding immediately every time a user hovers over a box; as just scrolling down the page would expand the boxes which would become extremely annoying. The boxes should only expand when the cursor is left over the box; lucky there&#8217;s a plug-in for jQuery that already adds this functionality, it&#8217;s called <a href="http://blog.threedubmedia.com/2008/08/eventspecialhover.html">$.event.special.hover</a>. </p>
<p>Special hover simply replaces the standard hover event with one that monitors the speed of the cursor over a set period of time. If the cursor speed drops below the threshold the hover event fires. This is enough to stop random hover events firing when a user navigates over the page, simple!</p>
<p>I&#8217;d be interested to see if the code works for others using <a href="http://wordpress.org/extend/plugins/codecolorer/">CodeColorer</a>, there&#8217;s no reason why it shouldn&#8217;t. <a href="http://nooshu.com/wp-content/uploads/downloads/codecolorer-expander.js">Download the code</a>, give it a try and let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/codecolorer-auto-expanding-code/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding WordPress Administrator User IDs</title>
		<link>http://nooshu.com/finding-wordpress-administrator-user-ids?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=finding-wordpress-administrator-user-ids</link>
		<comments>http://nooshu.com/finding-wordpress-administrator-user-ids#comments</comments>
		<pubDate>Wed, 10 Feb 2010 00:16:25 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=259</guid>
		<description><![CDATA[While adding a few features to Post Ideas+ I needed to find all the administrator IDs in Wordpress.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been adding a couple of new features to <a href="http://nooshu.com/wordpress-plug-in-post-ideas-plus/">Post Ideas+</a> over the past few days. One feature in particular required knowing the ID&#8217;s of users with the role of &#8216;administrator&#8217;. Now usually you can assume that the ID will be 1, as that&#8217;s what the initial adimin account setup by WordPress on install gets assigned. But as the code is going to be used in a plug-in you can&#8217;t really assume that.</p>
<p>Some people may have deleted the default account for security reasons (<a href="http://sixrevisions.com/wordpress/12-essential-security-tips-and-hacks-for-wordpress/">very good idea</a>) or they have more that one administrator account. After hunting about on the WordPress forums for a while I managed to piece together a little snippet of code to do this:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">//Get all admin user ID's in the DB</span><br />
<span style="color: #000000; font-weight: bold;">function</span> admin_user_ids<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Grab wp DB </span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Get all users in the DB</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$wp_user_search</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ID, display_name FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;users</span> ORDER BY ID&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Blank array</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$adminArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Loop through all users</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_user_search</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$userid</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Current user ID we are looping through</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$curID</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$userid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Grab the user info of current ID</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$curuser</span> <span style="color: #339933;">=</span> get_userdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$curID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Current user level</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$user_level</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$curuser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_level</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Only look for admins</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_level</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//levels 8, 9 and 10 are admin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Push user ID into array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$adminArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$curID</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$adminArray</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//Usage</span><br />
<span style="color: #000088;">$adminIdArray</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">admin_user_ids</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>I placed it into it&#8217;s own function within my plug-in Class so it can be called whenever needed. It could also be used for finding users with different <a href="http://codex.wordpress.org/User_Levels#User_Level_Capability_Table">levels</a> in WordPress if needed. If you wanted you could modify the function to accept an argument admin_user_ids($the_user_level_i_need); allowing you to get the IDs of users at whatever level you like.</p>
<p>There seemed to be a few ways of doing this on the forums, but this one works for me at the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/finding-wordpress-administrator-user-ids/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>More Frog CMS Magic</title>
		<link>http://nooshu.com/more-frog-cms-magic?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=more-frog-cms-magic</link>
		<comments>http://nooshu.com/more-frog-cms-magic#comments</comments>
		<pubDate>Mon, 08 Feb 2010 09:09:40 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[frogcms]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=239</guid>
		<description><![CDATA[Frog CMS can be made even simpler to implement with a couple of handy little code snippets.]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I was working working on a small website build that required a simple CMS so I decided to put <a href="http://www.madebyfrog.com/">Frog CMS</a> to use again; it continues to impress me. What at first looks like a very simple CMS actually has a powerful API behind it.</p>
<p>First thing I had to do (for my own sanity) was move the layout template outside of the CMS and into an external file. This gives you 2 advantages, you get to use whatever code editor you usually use to edit the template, and the file is then exposed so it can be committed to version control like any other file. It is simple to do with some very basic PHP:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/public/themes/yout-theme-directory/layout-template.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Paste that code in to your layout with a content type of &#8220;text/html&#8221; and you are done.</p>
<p>The second code snippet allows you to generate a specific ID and class for every page; great if you need some CSS style / JavaScript hooks on different pages.</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>url_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$bodyID</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$bodyID</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page-&quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slug</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slug</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;services&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$bodyClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;event&quot;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$bodyClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>The first if else statement simply sets the home ID to &#8220;home&#8221; then every other page to &#8220;page-slug-name-here&#8221; (slug is set in the &#8216;Meta&#8217; tab). The second one I use on &#8216;article&#8217; pages; it simply says if the current page has a parent and its parent is the services page add a class of &#8220;event&#8221;. So now I can style every article page in the same way, and it&#8217;s safe for a client to add event pages themselves.</p>
<p>You may ask why the &#8220;$this->parent()&#8221;; this is to stop the site breaking when you hit the home page since the homepage has no parent, it is the parent of all other pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/more-frog-cms-magic/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

