<?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; PHP Archives </title>
	<atom:link href="http://nooshu.com/tag/php/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>Adding a custom header image to your WordPress theme</title>
		<link>http://nooshu.com/adding-a-custom-header-image-to-your-wordpress-theme?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-a-custom-header-image-to-your-wordpress-theme</link>
		<comments>http://nooshu.com/adding-a-custom-header-image-to-your-wordpress-theme#comments</comments>
		<pubDate>Thu, 23 Sep 2010 07:54:45 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1379</guid>
		<description><![CDATA[Adding a custom header image to a Wordpress theme has never been so easy. Simply copy / paste and edit the code listed.]]></description>
			<content:encoded><![CDATA[<p>Every new iteration of WordPress (version 3.0.1 at the time of writing) brings a host of new features and bug fixes. One feature that I completely missed in 3.0 was the new custom header functionality. Before 3.0 it would be a case of hacking together your own solution using custom fields or using a separate plug-in. Thankfully the WordPress team have added this functionality directly to the core.</p>
<p>It just so happens that I&#8217;ve had a request for a customisable header image on an future project, so decided to have a play and see how difficult it is to implement. Well it isn&#8217;t difficult at all, very simple in fact.</p>
<p>First you will need to edit your functions.php located in your theme directory. Go ahead and create one if it isn&#8217;t in the directory. Now copy and paste the code below into the file. I&#8217;ve commented the code but it&#8217;s all quite self explanatory. Change the height and width of the image and change the directories where needed.</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:404px;"><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 />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<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 />
<span style="color: #666666; font-style: italic;">//Check see if the customisetheme_setup exists</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'customisetheme_setup'</span><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;">//Any theme customisations contained in this function</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> customisetheme_setup<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: #666666; font-style: italic;">//Define default header image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'HEADER_IMAGE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%s/header/default.jpg'</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: #666666; font-style: italic;">//Define the width and height of our header image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'HEADER_IMAGE_WIDTH'</span><span style="color: #339933;">,</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'customisetheme_header_image_width'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">960</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: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'HEADER_IMAGE_HEIGHT'</span><span style="color: #339933;">,</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'customisetheme_header_image_height'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">220</span> <span style="color: #009900;">&#41;</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: #666666; font-style: italic;">//Turn off text inside the header image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'NO_HEADER_TEXT'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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: #666666; font-style: italic;">//Don't forget this, it adds the functionality to the admin menu</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add_custom_image_header<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'customisetheme_admin_header_style'</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: #666666; font-style: italic;">//Set some custom header images, add as many as you like</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//%s is a placeholder for your theme directory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$customHeaders</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Image 1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'perfectbeach'</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; <span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%s/header/default.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumbnail_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%s/header/thumbnails/pb-thumbnail.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Perfect Beach'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'customisetheme'</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <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;">//Image 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'tiger'</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; <span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%s/header/tiger.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumbnail_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%s/header/thumbnails/tiger-thumbnail.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Tiger'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'customisetheme'</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <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;">//Image 3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'lunar'</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; <span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%s/header/lunar.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumbnail_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%s/header/thumbnails/lunar-thumbnail.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Lunar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'customisetheme'</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Register the images with Wordpress</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; register_default_headers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$customHeaders</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'customisetheme_admin_header_style'</span> <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;">//Function fired and inline styles added to the admin panel</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Customise as required</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> customisetheme_admin_header_style<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;style type=&quot;text/css&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #wpbody-content #headimg {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> HEADER_IMAGE_HEIGHT<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> HEADER_IMAGE_WIDTH<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border: 1px solid #333;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/style&gt;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//Execute our custom theme functionality</span><br />
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'after_setup_theme'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'customisetheme_setup'</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>By adding the code above you will now see a new option under &#8220;Appearance&#8221; in the admin panel called &#8220;Header&#8221;. From there you should be able to see all the images and options we just set in the functions.php file. The only thing left to do now is add the header image to the theme.</p>
<p>Where you place the following code will be depend on your theme setup; I&#8217;ve decided to place it in the header.php file as I want the image to appear on every page. You may only want the image to appear on specific templates e.g. pages, archive, category (you could also use <a href="http://codex.wordpress.org/Conditional_Tags">WordPress conditional tags</a> to do this).</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: #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;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- other header code here.... --&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- This line adds the header to the theme --&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;headerimg&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php header_image(); ?&gt;</span></span>&quot; width=&quot;<span style="color: #009900;">&lt;?php echo HEADER_IMAGE_WIDTH; ?&gt;</span>&quot; height=&quot;<span style="color: #009900;">&lt;?php echo HEADER_IMAGE_HEIGHT; ?&gt;</span>&quot; alt=&quot;Header image alt text&quot; /&gt;<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>And there you have it, one header image that you can customise via the WordPress admin panel. An ID is attached to the image for CSS styling where needed.</p>
<p>The example above is quite a simplified version of the header image functionality. It is possible to place text over the image and even have a different image per blog post by using the custom thumbnail functionality, but these are beyond the scope of this blog post. Copy &#038; paste and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/adding-a-custom-header-image-to-your-wordpress-theme/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Drupal Love! Stuff I&#8217;ve learnt!</title>
		<link>http://nooshu.com/drupal-love-stuff-ive-learnt?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drupal-love-stuff-ive-learnt</link>
		<comments>http://nooshu.com/drupal-love-stuff-ive-learnt#comments</comments>
		<pubDate>Thu, 09 Sep 2010 21:47:13 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1372</guid>
		<description><![CDATA[A little bit of Drupal knowledge goes a long way! This amazing open source CMS allows you to build large scale websites easily.]]></description>
			<content:encoded><![CDATA[<p>I created a <a href="http://nooshu.com/new-to-drupal-here-are-a-few-helpful-links/">post a couple of months ago</a> about how I was learning <a href="http://drupal.org/">Drupal</a> for an up and coming project; well that project finally went live this week. Huzzah! It wasn&#8217;t all smooth sailing; there was lots of trial and error, head scratching and a few mini panics, but I got there in the end. It&#8217;s amazing what you learn over the course of a project. Any future Drupal projects will be so much quicker and easier to setup due to the fact that I now actually know how to use Drupal!</p>
<p>So anyway here are a few things I learnt along the way:</p>
<ul>
<li>There are some <a href="http://drupal.org/node/190815">very simple yet powerful</a> templating rules you can use to style your website. Learning how they work will really help you style specific pages and blocks.</li>
<li>Looking for some functionality that is missing by default? I bet there&#8217;s already a module that does the job. Check out <a href="http://drupalmodules.com/">Drupal modules</a>, this excellent website lists and rates thousands of Drupal modules which you can install and use.</li>
<li>If you do find a module that adds the functionality you need, double check that there aren&#8217;t other modules about that do it better. Since Drupal has been around for some time, many modules haven&#8217;t been updated in quite a while so they may just be occupying the name space. It&#8217;s always best to check before you dive into using one particular module as it may not always be the best route to take.</li>
<li>Learn how to use the <a href="http://drupal.org/project/cck">Content Construction Kit</a> (CCK). If you are missing a type of CCK field, look for an additional module; I&#8217;m sure there will be one you can install that does the job. You really can make content types do anything you want with CCK.</li>
<li>Learn how to use the <a href="http://drupal.org/project/views">Views module</a>. I really can&#8217;t express this point enough. The Views module is without a doubt one of the most powerful additions to any CMS I&#8217;ve ever come across. With it you can take any content and display it however you like on a page. The layout is a little intimidating at first, but once you get your head round it you will have a dynamic site up and running in no time at all.</li>
<li>Install the <a href="http://drupal.org/project/imagecache">ImageCache module</a>. It ties in with both CCK and Views allowing you to upload and display images on your site however you need to. If you add a new image preset the module will automatically iterate over old images so you never have to go in and manually adjust images if you change your site design / functionality.</li>
<li>One thing I missed from Drupal was the ability to add parent / child nodes. Luckily theres a module called <a href="http://drupal.org/project/nodehierarchy">Node Hierarchy</a> that will add this functionality. It even handles the breadcrumbs and Views for you. <strong>Note</strong>: Make sure you don&#8217;t have &#8216;Taxonomy breadcrumb&#8217; enabled with Node Hierarchy as the breadcrumbs won&#8217;t work. I learnt that the hard way!</li>
</ul>
<p>Hopefully other budding Drupal users found the tips helpful. I&#8217;m still a Drupal novice, but now I know the basics the site possibilities are endless.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/drupal-love-stuff-ive-learnt/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plug-in: Snipplr Snippets</title>
		<link>http://nooshu.com/wordpress-plug-in-snipplr-snippets?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-plug-in-snipplr-snippets</link>
		<comments>http://nooshu.com/wordpress-plug-in-snipplr-snippets#comments</comments>
		<pubDate>Thu, 24 Jun 2010 15:27:05 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[snipplr]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1230</guid>
		<description><![CDATA[Having a little time to spare I decided to update the Snipplr Plug-in for Wordpress, originally by Tyler Hall.]]></description>
			<content:encoded><![CDATA[<p>Recently I blogged about the fact that <a href="http://nooshu.com/snipplr-under-new-management/">Snipplr was under new management!</a>, and what great news that is. You can see the changes being made already, fingers crossed they manage to nail the spam issue.</p>
<p>Back when Snipplr was young, Tyler Hall wrote a WordPress plug-in for Snipplr that allowed you to embed your snippets directly into your posts. What a great idea; unfortunately it hasn&#8217;t been updated since 2006 and much has changed in the world of WordPress. Enabling the plug-in in it&#8217;s current state is a little flakey; so I&#8217;ve decided to update it for WordPress 3.0+.</p>
<p>The plug-in is called &#8216;Snipplr Snippets&#8217; and is available to download from the <a href="http://wordpress.org/extend/plugins/snipplr-snippets/">WordPress plug-in repository</a>. I&#8217;ve used many of the functions that were in the old plug-in so it isn&#8217;t a complete rewrite but much of the structure has changed (big thank you to Marcin Dominas helped with a couple of issues i was having at first).</p>
<div id="attachment_1232" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/06/snipplr-snippets-sidebar.gif"><img src="http://nooshu.com/wp-content/uploads/2010/06/snipplr-snippets-sidebar-518x359.gif" alt="View of the snippler snippets side bar." title="snipplr-snippets-sidebar" width="518" height="359" class="size-medium wp-image-1232" /></a><p class="wp-caption-text">Snipplr Snippets sidebar widget in action.</p></div>
<p>The administrator area has been updated and there are a couple of new features available which hopefully are self explanatory. I&#8217;ve also updated to the latest version of GeSHi for the syntax highlighting, if you don&#8217;t like the look a feel of the outputted code simply disable the plug-in CSS in the site header (admin panel), copy to your style.css and modify as needed. For the plug-in to work you will need a <a href="http://snipplr.com/">Snipplr account</a> and an <strong>API key</strong> (available from the settings page).</p>
<p>Once you&#8217;ve installed the plug-in and enabled it, it&#8217;s dead simple to include a snippet into your blog post like so:</p>
<div class="codecolorer-container text 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">//Remove the spaces inside the brackets. <br />
[ snippet id=## ]</div></td></tr></tbody></table></div>
<p>Where the ## is the ID of the snippet you wish to include in the post (you can get this from the snippet URL). The code below is pulling in a snippet directly from Snipplr using the plug-in:</p>
<div class='sniplrcode'>
<ol class="jquery" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">$</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">$</span><span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<a href="http://docs.jquery.com/Ajax/load"><span style="color: #000066;">load</span></a><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></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Wait for the page to load, the cache the files you want</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">$</span>.<a href="http://docs.jquery.com/Ajax/ajax"><span style="color: #000066;">ajax</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;javascript.js&#8217;</span><span style="color: #339933;">,</span> dataType<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;text&#8217;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">$</span>.<a href="http://docs.jquery.com/Ajax/ajax"><span style="color: #000066;">ajax</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;image.jpg&#8217;</span><span style="color: #339933;">,</span> dataType<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;text&#8217;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">$</span>.<a href="http://docs.jquery.com/Ajax/ajax"><span style="color: #000066;">ajax</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;flash.swf&#8217;</span><span style="color: #339933;">,</span> dataType<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;text&#8217;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">$</span>.<a href="http://docs.jquery.com/Ajax/ajax"><span style="color: #000066;">ajax</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;style.css&#8217;</span><span style="color: #339933;">,</span> dataType<span style="color: #339933;">:</span><span style="color: #3366CC;">&#8216;text&#8217;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><a href="http://docs.jquery.com/Core/jQuery"><span style="color: #000066;">jQuery</span></a><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
</ol>
</div>
<p>I&#8217;ve tested the plug-in and it seems to work fine, there was a warning from the CodeColorer plug-in because it also uses GeSHi for syntax highlighting but I haven&#8217;t noticed anything break because of it. If it does please let me know and I&#8217;ll fix it. If you have any suggestions / bugs leave a comment and I&#8217;ll see what look into implementing / fixing them. <a href="http://wordpress.org/extend/plugins/snipplr-snippets/">Download here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/wordpress-plug-in-snipplr-snippets/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using the DeviceAtlas API with WordPress</title>
		<link>http://nooshu.com/using-the-deviceatlas-api-with-wordpress?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-the-deviceatlas-api-with-wordpress</link>
		<comments>http://nooshu.com/using-the-deviceatlas-api-with-wordpress#comments</comments>
		<pubDate>Tue, 22 Jun 2010 20:14:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1221</guid>
		<description><![CDATA[Building a mobile site can be quite painful, but it's made much easier using the DeviceAtlas API.]]></description>
			<content:encoded><![CDATA[<p>Over the past couple of weeks I&#8217;ve had the absolute pleasure (no not really!) of adapting a WordPress site and making it accessible on as many mobile phones as possible. Now I must admit I&#8217;ve not had much experience building mobile sites so this is all new ground for me; and by mobile website I don&#8217;t mean for the iPhone only (for more information on this plus lots of swear words see &#8216;<a href="http://www.quirksmode.org/blog/archives/2010/02/the_iphone_obse.html">The iPhone Obsession</a>&#8216; by PPK).</p>
<p>Luckily there are already many plug-ins available for WordPress that can get you started on your way, one that really grabbed my attention was  &#8216;<a href="http://mobiforge.com/running/story/the-dotmobi-wordpress-mobile-pack">WordPress Mobile Pack</a>&#8216; by MobiForge. The plug-in contains a mobile optimised theme that you can adapt for your needs and the &#8216;mobile switcher&#8217; functionality. Mobile switcher detects if a user is browsing from a desktop or a mobile phone and switched the theme accordingly. Great, we&#8217;re already half way there!</p>
<p>One of the specifications for the site was that it must work on a set of 4 different screen widths (480px, 320px, 240px and 176px) and this is where the DeviceAtlas API comes in very useful. Device Atlas keep a huge database of mobile phone user agent strings plus specifications associated with a particular mobile phone that you can tap into and use in your web application.</p>
<p>Now one thing I must mention is that according to the mobiForge page listed above, WordPress Mobile Pack includes DeviceAtlas integration. This turns out not to be the case. I couldn&#8217;t find any settings regarding DeviceAtlas in the plug-in admin area and very little mentioned on the forums. I assume the page hasn&#8217;t been updated for a while and the functionality has been removed. This isn&#8217;t a problem though as it&#8217;s fairly simple to integrate the DeviceAtlas API into your PHP application i.e. WordPress. Here&#8217;s how you do it.</p>
<p>First you must register with DeviceAtlas and order a developer licence (there&#8217;s a free option available <a href="http://deviceatlas.com/products">here</a>). Once registered grab a copy of the <a href="http://deviceatlas.com/downloads">PHP API</a> and the latest Device JSON file (under &#8216;My account&#8217;). Unpack the API into the root of your web application (or wherever you like, just make sure the includes are set correctly) and copy the JSON file into the json directory along side it. You are now ready to include the API into the base WordPress Mobile Pack theme. Copy and paste the following into your header.php above the doctype:</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 /></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 />
<span style="color: #666666; font-style: italic;">//Include the DA API</span><br />
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Mobi/Mtld/DA/Api.php'</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Include the JSON file with the device data</span><br />
<span style="color: #000088;">$tree</span> <span style="color: #339933;">=</span> Mobi_Mtld_DA_Api<span style="color: #339933;">::</span><span style="color: #004000;">getTreeFromFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'json/DeviceAtlas.json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Grab the User Agent string</span><br />
<span style="color: #000088;">$ua</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Great now we know the user agent that the user is using to view the website (well it may not be 100% accurate but better than nothing). So now you want to query the JSON file and pick out the relevant phone specifications you need. I&#8217;m just looking for the width of the device, so I included this in the head tag:</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 />14<br />15<br />16<br />17<br />18<br />19<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; try <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Query the JSON file ($tree) with the User Agent string and look for the display width</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">=</span> Mobi_Mtld_DA_Api<span style="color: #339933;">::</span><span style="color: #004000;">getPropertyAsInteger</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tree</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ua</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;displayWidth&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Mobi_Mtld_Da_Exception_InvalidPropertyException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">240</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Default to 240 if unknown</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Add stylesheet tweaks depending display width</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">480</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/480.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">320</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/320.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">240</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/240.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">176</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/176.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>All this code does is find the display width of the phone viewing the website and add a CSS file with relevant site tweaks, allowing you to optimise for that screen size. If the device isn&#8217;t found I&#8217;ve defaulted to a screen size in the middle of the screen sizes.</p>
<p>Looking through the API docs there are plenty of ways to distinguish between your users, using the following code will allow you to target specific phone brands:</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 /></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 />
<span style="color: #666666; font-style: italic;">//Output example $make = 'Nokia'</span><br />
<span style="color: #000088;">$make</span> <span style="color: #339933;">=</span> Mobi_Mtld_DA_Api<span style="color: #339933;">::</span><span style="color: #004000;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tree</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ua</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'vendor'</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>So now you can target only Nokia users. Or instead of loading a different CSS file you could include a different sized image for different screen widths; there are tonnes of options available.</p>
<p>I must admit I really dislike having to &#8216;sniff&#8217; for the user agent string and having a different CSS file / image per device width, it reminds me of the Netscape / IE browser war days, oh how much fun that was! I guess it&#8217;s a necessary evil. </p>
<p>A word or warning when it comes to DeviceAtlas, there seems to be distinct lack of support available. I wrote a couple of emails asking questions and got no reply, and lots of questions on the forum are left unanswered. So if you get stuck you may need to figure it out for yourself I&#8217;m afraid.</p>
<p>All in all I&#8217;m pleased with the results of my first adventure into the world of mobile web development. I still have lots to learn so if you have any tips and tricks please let me know! </p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/using-the-deviceatlas-api-with-wordpress/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress 3.0 RC1 blank page error</title>
		<link>http://nooshu.com/wordpress-3-0-rc1-blank-page-error?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-3-0-rc1-blank-page-error</link>
		<comments>http://nooshu.com/wordpress-3-0-rc1-blank-page-error#comments</comments>
		<pubDate>Wed, 02 Jun 2010 13:50:16 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[error]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1162</guid>
		<description><![CDATA[Upgrading to the latest version of Wordpress on my development server didn't quite go as smoothly as expected.]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: Apologies to the author of Hyper Cache, the error isn&#8217;t cause by the plug-in. The error is being caused by DB Cache Reloaded. After updating the site to 3.0 final I was getting the error on the update page, disabling DB Cache Reloaded fixed it.</p>
<p><strong>Update 2</strong>: DB Cache Reloaded has now been updated and works flawlessly in 3.0, get it <a href="http://wordpress.org/extend/plugins/db-cache-reloaded/">here</a>.</p>
<p>I&#8217;ve been eagerly awaiting the release of WordPress 3.0 (due any day now!). I plan on making a few changes to my blog once it is released so decided to try out <a href="http://wordpress.org/development/2010/05/wordpress-3-0-release-candidate/">Release Candidate 1</a> on my development server. At first it all went fine, upgraded the database no problem&#8230; then a blank page. Weird! After a couple of page reloads the sparkly new dashboard popped up (it&#8217;s not that different, although it does look greyer). Clicking around the admin area I could see this blank page error was randomly occurring on different pages; bugger!</p>
<p>My immediate thought was a plug-in I had installed, as I&#8217;m sure this rather large error would have been picked up while testing the WordPress core functionality! Looking at my Apache error log the following error was listed:</p>
<div class="codecolorer-container text 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="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[error] [client 127.0.0.1] PHP Fatal error: &nbsp;Call to undefined method wpdb::get_blog_prefix() in dev.nooshu.com\\trunk\\httpdocs\\wp-admin\\includes\\user.php on line 260, referer: http://dev.nooshu.com/wp-admin/edit.php?post_type=portfolio</div></td></tr></tbody></table></div>
<p>The error is too vague to actually help, but after a little investigating (and from a hunch I had) I disabled any plug-ins involved in page caching; namely DB Cache Reloaded <del datetime="2010-06-17T18:39:24+00:00">and Hyper Cache</del>. Unfortunately disabling them still didn&#8217;t fix the error, so I decided to remove them completely (db-config.ini, advanced-cache.php and db.php removed from the wp-content directory). Suddenly no more blank page errors occurring! Huzzah!</p>
<p>So if you come across the same problem, then check what caching plug-ins you have installed. When 3.0 final is released I&#8217;ll be doing a fresh install of both plug-ins. Hopefully that will solve the issue. They are both quite popular plug-ins so I&#8217;m sure others have had the same issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/wordpress-3-0-rc1-blank-page-error/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NextGEN Gallery + WordPress custom fields = happy developer</title>
		<link>http://nooshu.com/nextgen-gallery-wordpress-custom-fields-happy-developer?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nextgen-gallery-wordpress-custom-fields-happy-developer</link>
		<comments>http://nooshu.com/nextgen-gallery-wordpress-custom-fields-happy-developer#comments</comments>
		<pubDate>Thu, 20 May 2010 16:23:49 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[nextgen]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1128</guid>
		<description><![CDATA[When combining NextGEN gallery and built in Wordpress custom fields you can add some superb functionality which is easy to use.]]></description>
			<content:encoded><![CDATA[<p>Over the past couple of weeks I&#8217;ve been working on a number of WordPress projects, all of which have needed some basic photo gallery functionality. As I&#8217;ve mentioned before in <a href="http://nooshu.com/shadowbox-and-nextgen-gallery-sitting-in-a-tree/">previous posts</a>, <a href="http://wordpress.org/extend/plugins/nextgen-gallery/">NextGEN gallery</a> is my WordPress gallery of choice, there really is nothing that comes close to it in terms of features and customisation (that I know of, if there are others post a comment!).</p>
<p>To add a gallery (or album) to a post / page is as simple as adding &#8216;[ nggallery id=x ]&#8216; to the post content&#8230; super! One issue though&#8230; what happens when you allow a client to edit and add new pages; well what usually happens is the tag gets deleted or changed, the gallery breaks, client panics and the virtual world ends (well not quite, but close). A technique I have been using to help solve this issue involves using WordPress custom fields and the excellent <a href="http://wordpress.org/extend/plugins/get-custom-field-values/">Get custom field values plug-in</a>. You can grab the custom field values directly from WordPress using get_post_meta() but the plug-in makes it much easier.</p>
<p>Digging through the nggfunctions.php file in the NextGEN gallery plug-in folder reveals a whole host of useful functions that can be easily called directly from inside your WordPress theme. So say you wanted a gallery in a post page, but didn&#8217;t want the client to have to remember &#8216;[ nggallery id=x ]&#8216; every time, simply add this code next to your content in the single.php file:</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;">&lt;?php</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>c2c_get_current_custom<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'galleryID'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$gID</span> <span style="color: #339933;">=</span> c2c_get_current_custom<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'galleryID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> nggShowGallery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gID</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 />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Add a custom field of galleryID with an integer value linking to the relevant gallery and you&#8217;re done. Now the client can pick out the galleryID custom field from a drop-down since WordPress remembers the custom fields used. Much easier for a client to remember than adding the tag every time.</p>
<p>I highly recommend looking through the nggfunctions.php file, here are just a few functions that are available:</p>
<ul>
<li><strong>nggShowAlbum()</strong>: Show a whole album depending on the ID.</li>
<li><strong>nggSinglePicture()</strong>: Show a single picture from an ID.</li>
<li><strong>nggShowRandomRecent()</strong>: Show random image(s) from a certain gallery.</li>
<li><strong>nggShowSlideshow()</strong>: Show a flash slideshow pulling images from a specified gallery.</li>
</ul>
<p>I have used nggShowRandomRecent() quite a few times in the past few months, here&#8217;s a quick example:</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 /></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: #666666; font-style: italic;">//Show 6 random images using 'my-template' from gallery 4</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//(order, number of images, template, gallery ID)</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> nggShowRandomRecent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'random'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my-template'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</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>Pick 6 images at random from a selected gallery on page load, very simple and effective.</p>
<p><strong>Note</strong>: When using the random images function make sure you don&#8217;t have any WordPress caching plug-ins running on the selected page, else it won&#8217;t work as the page gets cached on first load. It took me a good 15 minutes to figure out why the function had suddenly stopped working due to this slight oversight.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/nextgen-gallery-wordpress-custom-fields-happy-developer/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Wolf CMS: A fork of Frog CMS</title>
		<link>http://nooshu.com/wolf-cms-a-fork-of-frog-cms?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wolf-cms-a-fork-of-frog-cms</link>
		<comments>http://nooshu.com/wolf-cms-a-fork-of-frog-cms#comments</comments>
		<pubDate>Sun, 09 May 2010 17:41:47 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[frogcms]]></category>
		<category><![CDATA[wolfcms]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1108</guid>
		<description><![CDATA[I've used Frog CMS on small projects in the past and have been very impressed, but there looks to be a fork on the horizon...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written about my <a href="http://www.madebyfrog.com/">Frog CMS</a> usage in <a href="http://nooshu.com/frog-cms-nice-and-simple-cms/">previous blog posts</a>; where other CMS&#8217;s can be a little overkill for small websites, Frog CMS fits perfectly into the gap. Unfortunately as much as I like Frog, the development seems to have stopped. The last stable version was released on the 26th April 2009, over a year ago. There&#8217;s no need to panic though, a development fork has been created called <a href="http://www.wolfcms.org/">Wolf CMS</a> which is building upon this superb little CMS and making it even better!</p>
<p>At the moment there&#8217;s very little difference between Frog and Wolf as you might expect, so migrating from one to the other is fairly simple, a wiki page has been created with instructions on <a href="http://www.wolfcms.org/wiki/migrating_from_frog_to_wolf_cms">how to do this</a>. As it says on the page it&#8217;s probably best to decide between the two versions now since there&#8217;s still little difference between them, but this could change in future versions (version 0.6.0 introduced a number of large changes). So there may be a point where it isn&#8217;t (easily) possible to jump between the two versions.</p>
<p>So what are the differences at the moment? When version 0.6.0 of Wolf CMS was released on the 1st February it added a new core plug-in called &#8216;BackupRestore&#8217;, allowing admin users to easily backup the Wolf CMS core DB tables. I&#8217;ve been using an external plug-in to do this on sites I built, so having this feature added as a core plug-in is nifty addition. Other features include:</p>
<ul>
<li>Admin users can now uninstall plug-ins, including the db tables</li>
<li>HTTPS Support added to the admin area for greater security</li>
<li>You can now preview a page before it is published</li>
</ul>
<p>It&#8217;s great to see that such a useful little CMS hasn&#8217;t been left to stagnate and die out, the <a href="http://www.wolfcms.org/about/project-roadmap.html">roadmap</a> for Wolf CMS looks promising, so fingers crossed it has a bright future ahead of it. I think it&#8217;s time to migrate my Frog websites over to Wolf&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/wolf-cms-a-fork-of-frog-cms/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing your WordPress Sidebar Markup</title>
		<link>http://nooshu.com/changing-your-wordpress-sidebar-markup?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=changing-your-wordpress-sidebar-markup</link>
		<comments>http://nooshu.com/changing-your-wordpress-sidebar-markup#comments</comments>
		<pubDate>Wed, 03 Mar 2010 20:52:46 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=351</guid>
		<description><![CDATA[Sometimes the default markup for for the Wordpress sidebar isn't quite what you need. Here's how you change it.]]></description>
			<content:encoded><![CDATA[<p>While creating a theme for WordPress today I ran into a little problem with my sidebar; the layout of the sidebar didn&#8217;t quite fit my needs for the design in-hand. At first I thought it could be a case of delving into the WordPress core code that generates all the widgets and modifying where needed, but that isn&#8217;t much fun. You also run the rist of these changes being overwritten next time you update WordPress; there had to be another way.</p>
<p>Purely for styling I needed to add an extra span to the title and a div to the widget wrapper. After searching through the <a href="http://codex.wordpress.org/">Codex</a> I came across the perfect <a href="http://codex.wordpress.org/Function_Reference/register_sidebars">solution</a>:</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 /></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;">//Custom settings in associative array</span><br />
<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'before_widget'</span> &nbsp;<span style="color: #339933;">=&gt;</span> &nbsp; <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;&lt;div class=&quot;inner&quot;&gt;'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'after_widget'</span> &nbsp; <span style="color: #339933;">=&gt;</span> &nbsp; <span style="color: #0000ff;">&quot;&lt;/div&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'before_title'</span> &nbsp; <span style="color: #339933;">=&gt;</span> &nbsp; <span style="color: #0000ff;">'&lt;h3 class=&quot;widgettitle&quot;&gt;&lt;span&gt;'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'after_title'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> &nbsp; <span style="color: #0000ff;">&quot;&lt;/span&gt;&lt;/h3&gt;&quot;</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Check for register function and register the sidebar</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebars'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; register_sidebars<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>You simply create an array with your custom settings and pass it into the register_sidebars function along with the number of sidebars you wish to register; paste that into the functions.php file in your theme and you&#8217;re done. If you don&#8217;t have a functions.php file you can just create one. All the settings are pretty self-explanatory and with these changing widget markup is easy.</p>
<p>On a side note; I&#8217;ve never been a big fan of using nested lists in the sidebar, I&#8217;m not sure it&#8217;s semantically correct; but I guess it does the job and works even when CSS is disabled.</p>
<p>You learn something new everyday!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/changing-your-wordpress-sidebar-markup/feed</wfw:commentRss>
		<slash:comments>0</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>

