<?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; Wordpress Archives </title>
	<atom:link href="http://nooshu.com/tag/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://nooshu.com</link>
	<description>Kneeling on the shoulders of giants</description>
	<lastBuildDate>Fri, 20 Jan 2012 11:38:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WordPress 3.2, auto update fail</title>
		<link>http://nooshu.com/wordpress-3-2-auto-update-fail?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-3-2-auto-update-fail</link>
		<comments>http://nooshu.com/wordpress-3-2-auto-update-fail#comments</comments>
		<pubDate>Tue, 05 Jul 2011 19:34:24 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[broke]]></category>
		<category><![CDATA[cry]]></category>
		<category><![CDATA[fail]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1759</guid>
		<description><![CDATA[The Wordpress auto update feature is superb; when it works. When it doesn't it can make you cry. Luckily there can be a quick fix.]]></description>
			<content:encoded><![CDATA[<p>Today, while on my lunch hour, I decided to auto update my blog to WordPress 3.2. Usually it goes without a hitch; unfortunately today it didn&#8217;t. I&#8217;m not quite sure what happened but it failed within a couple of seconds. Damn it! It may be a <a href="http://www.dreamhost.com/" title="Dreamhost hosting">Dreamhost</a> issue as I&#8217;ve seen reports of other users having similar issues, or it could be just bad luck.</p>
<p>If you have a similar issue the first thing you may notice, when trying to get to your site is that maintenance mode is &#8220;enabled&#8221;. To disable this connect to hosting server via FTP (or SSH) and delete the file &#8216;.maintenance&#8217;. The file may be hidden so you may have to enable viewing hidden files in your FTP client. Once deleted you should once again be able to see your site (fingers crossed!).</p>
<p>The next issue I had was not being able to log into my site admin panel. Navigating to the page gave me a horrible fatal PHP error; a sure sign that something was very broken. Not to worry there&#8217;s a (fairly) simple fix.</p>
<p>While logged onto your server via FTP or SSH, delete the &#8216;wp-admin&#8217; and the &#8216;wp-includes&#8217; folder. Make sure you <strong>don&#8217;t</strong> delete the &#8216;wp-content&#8217; folder! Once that&#8217;s done <a href="http://wordpress.org/download/" title="Wordpress 3.2 download">download a copy</a> of WordPress 3.2, unzip it and upload the unzipped &#8216;wp-admin&#8217; and the &#8216;wp-includes&#8217; folders to your server. Once complete you should be able to see your WordPress login page again! Yay!</p>
<p>You may be asked to update your database, go ahead and click the update button and login. Now take in all the goodness that is version 3.2 of WordPress! The guys have done a superb job with the admin panel, love the new design. Glad to hear they have also <a href="http://en.blog.wordpress.com/2011/05/19/just-write/" title="IE6 is no more!">dropped IE6 support</a> too. About bloody time!</p>
<p>So a quick summary for the tr;dr&#8217;s out there:</p>
<ol>
<li>Maintenance mode on? Delete &#8216;.maintenance&#8217;.</li>
<li>Delete &#8216;wp-admin&#8217; and the &#8216;wp-includes&#8217; folders (<strong>Not &#8216;wp-content&#8217;!</strong>)</li>
<li>Download a copy of WordPress and unzip it.</li>
<li>Upload the unzipped &#8216;wp-admin&#8217; and the &#8216;wp-includes&#8217; folders.</li>
<li>Navigate to the admin page, update database and login</li>
</ol>
<p>Phew, crisis averted! Now&#8217;s a good time to reiterate what is mentioned on the updates page. Always remember to back-up your database and files before you run an update. If something does break with the auto update you can always revert to your backup!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/wordpress-3-2-auto-update-fail/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Aloha Editor and WordPress</title>
		<link>http://nooshu.com/aloha-editor-and-wordpress?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=aloha-editor-and-wordpress</link>
		<comments>http://nooshu.com/aloha-editor-and-wordpress#comments</comments>
		<pubDate>Thu, 09 Jun 2011 21:13:06 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[wysiwyg]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1747</guid>
		<description><![CDATA[What could make Wordpress any better? What about the ability to edit your posts directly in the page? Yay!]]></description>
			<content:encoded><![CDATA[<p>This is a short update on a post I wrote back in August 2010 &#8211; <a href="http://nooshu.com/aloha-editor-content-editing-the-html5-way">Aloha Editor, content editing the HTML5 way</a>. When I last looked at the project there were some excellent examples of it working on static pages but no real integration into back-end systems had taken place. As with any open-source project things progress quickly; on the 5th June a plug-in called <a href="http://wordpress.org/extend/plugins/front-end-editor/">Front-end Editor</a> for WordPress was updated to include Aloha Editor! You can now edit blog posts directly in the page rather than through the administration panel. The plug-in is a joint effort from authors Jotschi and Scribu, excellent work guys.</p>
<div id="attachment_1750" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2011/06/aloha-wordpress.gif"><img src="http://nooshu.com/wp-content/uploads/2011/06/aloha-wordpress.gif" alt="Aloha Editor in WordPress using Front-end Editor" title="aloha-wordpress" width="518" height="331" class="size-full wp-image-1750" /></a><p class="wp-caption-text">Edit a post directly in the page, the future is here.</p></div>
<p>Now I&#8217;d love to show you a picture of it working in my blog template, but that would be too easy wouldn&#8217;t it. :) Unfortunately the plug-in doesn&#8217;t work with my custom theme, I&#8217;m yet to figure out the reason why. Boo! I know it isn&#8217;t a plug-in issue as it works with the <a href="http://2010dev.wordpress.com/">default WordPress theme</a>. This could be an issue for others wanting to use the plug-in, so as soon as I figure out why I&#8217;ll post an update.</p>
<p>One issue I did notice was Aloha likes to use its own version of jQuery; manually including it in your theme will cause Aloha to throw an error. A quick workaround is to wrap a <a href="http://codex.wordpress.org/Conditional_Tags">WordPress conditional tag</a> around the jQuery script element like so:</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: #666666; font-style: italic;">//If you aren't logged in, include jQuery</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">//Insert jQuery script tag here</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Since you need to be logged in for Aloha to be initialised this will fix the error and allow you to use the latest version of jQuery in your theme.</p>
<p>As soon as I fix Front-End Editor for my current theme I&#8217;m sure it will be one of my favourite plug-ins. Last but not least a big thank you to the Aloha Editor team, I&#8217;m looking forward to seeing how the project progresses.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/aloha-editor-and-wordpress/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Stats broken? Grab yourself a Jetpack!</title>
		<link>http://nooshu.com/wordpress-stats-broken-grab-yourself-a-jetpack?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-stats-broken-grab-yourself-a-jetpack</link>
		<comments>http://nooshu.com/wordpress-stats-broken-grab-yourself-a-jetpack#comments</comments>
		<pubDate>Tue, 22 Mar 2011 21:47:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1628</guid>
		<description><![CDATA[Have your Wordpress Stats broke? Feel a little lost without that friendly graph on the Dashboard? You need Jetpack!]]></description>
			<content:encoded><![CDATA[<p>Last week one of my favourite WordPress plug-ins broke: <a href="http://wordpress.org/extend/plugins/stats/">WordPress Stats</a>. For anyone who doesn&#8217;t use this fantastic plug-in it&#8217;s a very clean and simple way of viewing visitor statistics directly on your dashboard. It isn&#8217;t as extensive as Google Analytics and for that I&#8217;m grateful as it doesn&#8217;t need to be. I first thought it was a hosting issue but that turned out to be incorrect. The plug-in, in it&#8217;s current form has been discontinued as it has been rolled into a compilation of useful WordPress tools called <a href="http://wordpress.org/extend/plugins/jetpack/">Jetpack</a>.</p>
<p>So what do you get in Jetpack? Well here are three of my favourites:</p>
<ul>
<li><strong>WordPress.com Stats</strong> &#8211; exactly what it says on the tin&#8230;</li>
<li><strong>Shortcode Embeds</strong> &#8211; easily add media from YouTube, Vimeo and Slideshare.</li>
<li><strong>LaTeX</strong> &#8211; need equations in a blog post? This ones for you then.</li>
</ul>
<p>There are eight plug-ins currently available with more coming soon.</p>
<p>The last plug-in I mentioned, LaTeX may sound like it&#8217;s come straight from a .xxx domain name but bare with me; under that slightly suspect name is a powerful tool for anyone who needs to format equations in a post. Here&#8217;s a small demonstration:</p>
<p><img src='http://s0.wp.com/latex.php?latex=e%5E%7Bi%5Cpi%7D+%2B+1+%3D+0&#038;bg=D7DBCD&#038;fg=000&#038;s=3' alt='e^{i&#92;pi} + 1 = 0' title='e^{i&#92;pi} + 1 = 0' class='latex' /></p>
<p>LaTeX has allowed me to embed one of the most beautiful equations in all of mathematics; Euler&#8217;s Equation directly into my blog post. It links Real Numbers, Euler&#8217;s Number, Imaginary Numbers and Pi in a staggeringly simple equation. There&#8217;s a mass of information on LaTeX <a href="http://en.wikibooks.org/wiki/LaTeX">here</a> with everything you&#8217;d ever need pretty much covered.</p>
<p>So if you&#8217;re looking to give your WordPress blog a bit of a boost (horrible pun I know), give <a href="http://wordpress.org/extend/plugins/jetpack/">Jetpack</a> a whirl!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/wordpress-stats-broken-grab-yourself-a-jetpack/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plug-ins and svn:externals</title>
		<link>http://nooshu.com/wordpress-plug-ins-and-svnexternals?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-plug-ins-and-svnexternals</link>
		<comments>http://nooshu.com/wordpress-plug-ins-and-svnexternals#comments</comments>
		<pubDate>Wed, 03 Nov 2010 13:05:18 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1446</guid>
		<description><![CDATA[So you have your Wordpress install in Subversion. What about those pesky plug-ins that always need updating.]]></description>
			<content:encoded><![CDATA[<p>So last week I decided to play with the <a href="http://nooshu.com/svn-post-commit-hook-on-dreamhost/">post-commit hook in Subversion</a> which allows you to easily update your WordPress install after committing changes to your repository. After some trial and error this works perfectly. One issue you may run into with WordPress when it&#8217;s committed to SVN is using the auto-update plug-in function.</p>
<p>Committing your plug-ins to SVN tends to break this (very cool) auto-update functionality. SVN adds a hidden &#8220;.svn&#8221; directory to each directory you commit. WordPress auto-update tries to delete the updating plug-ins folder before downloading and extracting the new version into the &#8220;wp-content/plugins directory&#8221;. WordPress isn&#8217;t able to delete the &#8220;.svn&#8221; directories so the auto update process fails, leaving you without the plug-in you were trying to update (since it deleted it before failing).</p>
<p>So what&#8217;s the solution? Well you could download the latest plug-in version and manually extract / commit it to your repository; but that&#8217;s too long winded (and boring). The ideal solution lies in the use of the svn:externals property. It allows you to attach an external repository location to a folder in your own repository. Since all WordPress plug-ins are hosted in the WordPress repository you can update all your plug-in&#8217;s directly from there with a quick &#8220;SVN Update&#8221;! Perfect!</p>
<p>You can do this via <a href="http://scott.yang.id.au/2006/04/svnexternal-wordpress-plugins/">SSH and the command line</a> or you can do it via a SVN client with a GUI (I use TortoiseSVN). I&#8217;ll be showing you how to do it via the GUI.</p>
<p>First you need to remove the plug-in you want to update from your repository if it&#8217;s been added. This may seem a little strange as you are trying to update it; but we need to update from an external repository and if a version already exists it will fail:</p>
<div id="attachment_1448" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/11/svn-delete-tortoise.gif"><img src="http://nooshu.com/wp-content/uploads/2010/11/svn-delete-tortoise-518x282.gif" alt="Delete the plug-in you wish to update" title="svn-delete-tortoise" width="518" height="282" class="size-medium wp-image-1448" /></a><p class="wp-caption-text">Delete the plug-in you need updating from the repository first</p></div>
<p>Next you need to setup your svn:externals property on the &#8220;wp-content/<strong>plugins</strong>&#8221; directory via the properties menu:</p>
<div id="attachment_1451" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/11/svn-tortoise-properties.gif"><img src="http://nooshu.com/wp-content/uploads/2010/11/svn-tortoise-properties-518x231.gif" alt="tortoise properties menu" title="svn-tortoise-properties" width="518" height="231" class="size-medium wp-image-1451" /></a><p class="wp-caption-text">Edit the properties on the 'plugins' directory.</p></div>
<p>Now for the tedious bit. For all the plug-ins you want SVN to auto-update, you will need to find the WordPress repository URL for. So for the example, to update Akismet and All in One SEO pack you will enter the following:</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">akismet http://plugins.svn.wordpress.org/akismet/trunk/<br />
all-in-one-seo-pack http://plugins.svn.wordpress.org/all-in-one-seo-pack/trunk/</div></td></tr></tbody></table></div>
<div id="attachment_1453" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/11/svn-tortoise-externals.gif"><img src="http://nooshu.com/wp-content/uploads/2010/11/svn-tortoise-externals-518x273.gif" alt="Using Tortoise SVN externals" title="svn-tortoise-externals" width="518" height="273" class="size-medium wp-image-1453" /></a><p class="wp-caption-text">Add the plug-in repositories to the externals properties, one per line.</p></div>
<p>Once you&#8217;ve added all the plug-ins you want to auto-update (remember to remove them first if they already exist in your repository!) commit your changes. Then watch the magic happen via an update:</p>
<div id="attachment_1454" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/11/svn-plugin-update.gif"><img src="http://nooshu.com/wp-content/uploads/2010/11/svn-plugin-update-518x262.gif" alt="Updating WordPress plugins directly from the repository" title="svn-plugin-update" width="518" height="262" class="size-medium wp-image-1454" /></a><p class="wp-caption-text">Plug-ins checked out from the WordPress repository.</p></div>
<p>Akismet and All in One SEO Pack have been checked out from the WordPress repository trunk. Every time you do an update SVN will check for new versions of the plug-ins. Great stuff! There is a slight warning with checking out from trunk; the developer could be working on a new release and unfinished code may have been committed, so the plug-in may be broken if updating from trunk! To get around this you may want to checkout from the plug-in tags (final versions) instead. To do that change the repository URLs to:</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">akismet http://plugins.svn.wordpress.org/akismet/tags/2.4.0/<br />
all-in-one-seo-pack http://plugins.svn.wordpress.org/all-in-one-seo-pack/tags/1.6.9/</div></td></tr></tbody></table></div>
<p>Unfortunately this will involve changing your svn:externals property every time a new version of a plug-in comes out, but it&#8217;s less likely your plug-ins will break. <strong>Note</strong>: Remember to replace the tag version number with the latest version. </p>
<p>I hope this little tip helps you streamline your deployment!</p>
<p><strong>P.S.</strong> On a side note, if anybody knows how to auto update from a tag automatically please leave a comment, I&#8217;d love to know if it&#8217;s possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/wordpress-plug-ins-and-svnexternals/feed</wfw:commentRss>
		<slash:comments>6</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>22</slash:comments>
		</item>
		<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>11</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>Headspace2 JavaScript error</title>
		<link>http://nooshu.com/headspace2-javascript-error?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=headspace2-javascript-error</link>
		<comments>http://nooshu.com/headspace2-javascript-error#comments</comments>
		<pubDate>Thu, 17 Jun 2010 19:25:35 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1209</guid>
		<description><![CDATA[Post Thesaurus is broken.... oh wait no it isn't. Just a pesky JavaScript error from another plugin!]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: An update of Headspace2 has just been released that seems to solve this issue as well as a few others.</p>
<p>After updating to WordPress 3.0 (yay!) I decided to check the plug-ins that I&#8217;ve written to see if they still worked in version 3.0; to my dismay <a href="http://wordpress.org/extend/plugins/post-thesaurus/">Post Thesaurus</a> had stopped working&#8230; nooooo! Not good! A quick scan using Firebug revealed the issue: the Headspace2 plug-in.</p>
<p><a href="http://wordpress.org/extend/plugins/headspace2/">Headspace2</a> is a superb plug-in that allows you to tweak the SEO potential of your site. There are tonnes of options available; All In One SEO is easier to use, but I prefer the flexibility of Headspace2. The problem was occurring in the headspace-tags.js file:</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 />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$(get_tag_element()).val() is undefined<br />
/wp-content/plugins/headspace2/js/headspace-tags.js?ver=3.6.32<br />
Line 76</div></td></tr></tbody></table></div>
<p>This error was stopping the rest of the JavaScript on a post page from firing (hence breaking Post Thesaurus). Looking at line 76 of headspace-tags.js you will see:</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 /></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;">// Highlights headspace tags using the WordPress tag field as source</span><br />
<span style="color: #003366; font-weight: bold;">function</span> highlight_tags <span style="color: #009900;">&#40;</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> words <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>get_tag_element<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The code seems to be falling over when there are no tags, so I just added a ternary operator which checks the array length first.</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 /></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: #003366; font-weight: bold;">var</span> words<span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> wordArray <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>get_tag_element<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#40;</span>wordArray.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> words <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>get_tag_element<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> words <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>If there are no tags create an empty array, else run the usual code. Adding this code fixed the issue and Post Thesaurus works again. Phew! Panic over. I&#8217;m sure this error will be picked up by the developer straight away and fixed in the next update.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/headspace2-javascript-error/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Converting a WordPress post to a custom post type</title>
		<link>http://nooshu.com/converting-a-wordpress-post-to-a-custom-post-type?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=converting-a-wordpress-post-to-a-custom-post-type</link>
		<comments>http://nooshu.com/converting-a-wordpress-post-to-a-custom-post-type#comments</comments>
		<pubDate>Thu, 03 Jun 2010 11:04:09 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1167</guid>
		<description><![CDATA[Converting your current posts isn't as easy as it looks. If you are comfortable editing the DB directly it's fairly simple.]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: There is now a plug-in that does this for you called <a href="http://wordpress.org/extend/plugins/post-type-switcher/">Post Type Switcher</a> so you don&#8217;t have to get your hands dirty with the SQL (thanks Bruno!). Another plug-in called <a href="http://sillybean.net/wordpress/new-plugin-convert-post-types/">Convert Post Types</a> is also available that does the job for you, Thanks to Steve for that one.</p>
<p>With the release of WordPress 3.0, developers now have the ability to create custom post types by adding a few lines of code to a themes functions.php. The feature is a huge step forwards for WordPress as it moves closer to being a viable CMS solution (without all the hacks). There have been a number of projects I&#8217;ve worked on that have required a custom post type; rather than relying on the client selecting the correct category under &#8216;Add new post&#8217;, which tends to always leads to issues.</p>
<p>I&#8217;m in the process of converting nooshu.com to use custom post types and taxonomies, the main area in particular is my <a href="http://nooshu.com/portfolio/">portfolio section</a>. At the moment the portfolio posts are just standard posts which have a category of &#8216;portfolio&#8217; attached to them. It works, but I don&#8217;t get that warm fuzzy feeling, and it feels like a bit of a hack. So time to start using a custom post type of &#8216;portfolio&#8217; (yay!).</p>
<p>Unfortunately at the moment there doesn&#8217;t seem to be a quick way of converting a published standard post into a shiny new custom post type, at least not from the administration area. After a little investigation work using <a href="http://www.phpmyadmin.net/home_page/">phpmyadmin</a> and the nooshu WordPress database, I discovered it&#8217;s actually quite easy. Be warned though, it&#8217;s easy to <strong>break your blog</strong> by editing the database directly, so make sure you back everything up. I take no responsibility for what happens if you break something!</p>
<p>To convert a post into a custom post type; in phpmyadmin look for the wp_posts table. Inside it do a search, where the &#8216;post_type&#8217; value equals &#8216;post&#8217;. This will give you a list of all your posts (otherwise you will also have all the revisions and attachments listed). From the list you should be able to pick out the posts you want converting to your new post type, edit one of these posts and change &#8216;post_type&#8217; from &#8216;post&#8217; to your new custom post. In my case this would be &#8216;portfolio&#8217;:</p>
<div id="attachment_1169" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/06/phpmyadmin-custom-post-type.gif"><img src="http://nooshu.com/wp-content/uploads/2010/06/phpmyadmin-custom-post-type-518x311.gif" alt="phpmyadmin admin panel for a WordPress post" title="phpmyadmin - custom post type" width="518" height="311" class="size-medium wp-image-1169" /></a><p class="wp-caption-text">Change 'post_type' from 'post' to your custom post type.</p></div>
<p>Click save and go back to the previous page. Done! You should now see the post appear under your new custom post type in the WordPress admin panel. If you have any issues just change &#8216;post_type&#8217; back to &#8216;post&#8217; and it will reappear under the standard posts. No information is lost when changing the post type.</p>
<p>It&#8217;s not an ideal solution, hopefully it will be possible to do it from the administration panel in the future; but it does save having to re-enter all the posts under the custom post type for the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/converting-a-wordpress-post-to-a-custom-post-type/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

