<?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>Tortoise IT &#187; Tutorials</title>
	<atom:link href="http://www.sean-barton.co.uk/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sean-barton.co.uk</link>
	<description>by Sean Barton, a freelance PHP website developer in Crewe, Cheshire</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:34:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Turn off theme CSS for the visual editor in WordPress 3.3+</title>
		<link>http://www.sean-barton.co.uk/2012/01/wordpress-visual-editor-css-deactivate/</link>
		<comments>http://www.sean-barton.co.uk/2012/01/wordpress-visual-editor-css-deactivate/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 10:59:32 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Bug Fixes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=701</guid>
		<description><![CDATA[It&#8217;s been on the cards for months and WordPress has finally added the inbuilt function whereby CSS files declared on the front end are now also declared on the edit item (post/page/custom post type) pages within the admin system. This is wonderful for some but, as someone who looks at a fair few sites using a range of free, premium and bespoke themes, actually it&#8217;s a curse in disguise. Let me explain&#8230; Let&#8217;s say you go to the WordPress theme repository and grab a nice free theme which has been written by a developer less than &#8216;au fait&#8217; with WordPress &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2012/01/wordpress-visual-editor-css-deactivate/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been on the cards for months and WordPress has finally added the inbuilt function whereby CSS files declared on the front end are now also declared on the edit item (post/page/custom post type) pages within the admin system. This is wonderful for some but, as someone who looks at a fair few sites using a range of free, premium and bespoke themes, actually it&#8217;s a curse in disguise. Let me explain&#8230;</p>
<p>Let&#8217;s say you go to the WordPress theme repository and grab a nice free theme which has been written by a developer less than &#8216;au fait&#8217; with WordPress functionality or best practice. You turn on the theme, all looks good and then go to write a post only to be presented with the page from hell because loose CSS rules used in style.css have broken the editor page look and feel all together. As there is no way in CSS to set a priority without rewriting the code itself you are left with a mess.</p>
<p>Pre WordPress 3.3 this wasn&#8217;t an issue as you needed to explicitly declare an editor style sheet in order to use the styles and make it look somewhat closer to that which you might find on the front end of the site.</p>
<p>Now.. turning it off! Well it will require some coding and in actual fact the simplest way to do anything about it is to make your stylesheet invisible to WordPress. Let me explain: The correct way to enqueue any CSS and JS on your site is to do something like the following:</p>
<pre>add_action('wp_print_styles', 'theme_add_stylesheet');
function theme_add_stylesheet() {
    wp_register_style('theme_stylesheet', get_stylesheet_directory_uri() . '/style.css');
    wp_enqueue_style( 'theme_stylesheet');
}</pre>
<p>This means that when the <em>wp_head</em> action is triggered from header.php in your theme the style will be printed to screen along with the other styles and scripts. The enqueue style function adds the name and location of the script to a global array which can be reused at any time. In short, WordPress knows that it is a CSS file declared by a plugin or theme and therefore can reuse it at will.</p>
<p>The fix is simple.. don&#8217;t use that method and, instead, use the original crude method of adding a stylesheet which is to write the HTML yourself as follows:</p>
<pre>&lt;link rel="stylesheet" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" type="text/css" media="screen" /&gt;</pre>
<p>This code, when placed in header.php of your theme, simply outputs the line in the head section of your page and includes the stylesheet unbeknown to WordPress and therefore won&#8217;t be used in the editor.</p>
<p>99% of the themes I have seen and used use the latter method so it&#8217;s not an issue but hopefully this will hel someone who has just upgraded and has some sort of multicoloured and wierdly laid out admin post page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2012/01/wordpress-visual-editor-css-deactivate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plugin queue jumping made easy</title>
		<link>http://www.sean-barton.co.uk/2012/01/wordpress-plugin-queue-jumping-easy/</link>
		<comments>http://www.sean-barton.co.uk/2012/01/wordpress-plugin-queue-jumping-easy/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 21:58:31 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Bug Fixes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=692</guid>
		<description><![CDATA[Hi all. Happy new year etc.. I have plenty of plans for the next 12 months but won&#8217;t go into them unlike every other person with a blog is undoubtedly doing at the moment. I want to keep this strictly useful information and me telling you I want to shift some weight, buy something or do something isn&#8217;t going to improve your lives any really is it. So here goes.. I have had an interesting problem for some months now which I have just solved albeit crudely! I have written several plugins and released them into the WordPress plugin repository &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2012/01/wordpress-plugin-queue-jumping-easy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright  wp-image-696" title="LEAPFROG" src="http://www.sean-barton.co.uk/wp-content/uploads/2012/01/LEAPFROG-300x279.jpg" alt="" width="210" height="195" />Hi all. Happy new year etc.. I have plenty of plans for the next 12 months but won&#8217;t go into them unlike every other person with a blog is undoubtedly doing at the moment. I want to keep this strictly useful information and me telling you I want to shift some weight, buy something or do something isn&#8217;t going to improve your lives any really is it. So here goes..</p>
<p>I have had an interesting problem for some months now which I have just solved albeit crudely! I have written several plugins and released them into the WordPress plugin repository as regular readers of this site might already know. What you are unlikely to know though is that in doing so all you get is an influx of support questions. I personally like these.. it gives me the illusion of helping people out whilst really knowing that it should have been right to begin with <img src='http://www.sean-barton.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The worst of these aforementioned support questions are to do with plugin conflicts. Cue potential threads and threads about how the &#8216;other guy&#8217; did something wrong which is going to need to poor user to go to their site/forum to get it sorted before our plugins can work in harmony as they were originally intended. This isn&#8217;t the best answer to a support question and certainly won&#8217;t get you any repeat custom. In all likelihood the user will ditch the plugin he finds least useful (yours.. after all he came to you to sort it in the first place meaning yours is likely the plugin they have just installed and are playing with) and install one of the other counterparts which undoubtedly does the same job but with umpteen donate buttons plastered all over it (I won&#8217;t go into that one right now but see <a href="http://www.sean-barton.co.uk/2011/12/donation-buttons-promotion-plugins-themes/">my previous post</a> for my thoughts on that particular subject).</p>
<p>One such example of a conflict I have been getting all year. It&#8217;s to do with my Welcome Email Editor plugin. WordPress does a fair few things very well indeed but sadly there are a few where it really could improve. This is why my Welcome Email Editor plugin exists at all. Can you guess what it does? Really? Ok so it lets you edit the WordPress welcome email.. the one that gives the user their user name and password if they decide to sign up for your site. The default offering is a little dull but luckily the guys who wrote WordPress have half heartedly thought about how it can be improved. Why let plugin writers like me do it of course. Sadly they opted not to use the action and filter system which already is ingrained in the rest of WordPress (for good reason I&#8217;m sure.. likely to do with load order) but instead just wrapped the entire wp_new_user_notification function in a PHP function called function_exists. This does what it says on the tin and only declares the function if someone else (a plugin or theme) doesn&#8217;t get there first.</p>
<p>In most cases this system works fine when you install a plugin dedicated to editing the welcome email and leave it at that. In reality most blogs have 30+ plugins active at any one time and probability and inevitability both say that more than one person is likely to want to jump on this handy feature for their plugin or theme. This means that one of the plugins needs to go! Normally if it were two plugins designed to edit the welcome email then we would be ok.. an obvious conflict of interest but what if one were a forum or shopping cart in conjunction with my plugin? Which goes then? Well the one which provides less functionality of course which, sadly, in that example would be my little plugin.</p>
<p>To make it somewhat more awkward, some plugins like to call WordPress core files directly thus causing the default function for the welcome email to be called before any other plugins and therefore chucking everyone else out of the race to declare the function first. Maintenance Mode is a plugin I know which does this when the system is active although it sorts itself out when you come out of maintenance mode so not really an issue. I have just been informed of another conflict with a plugin which makes dealing with WP Ecommerce in bulk easier (and we all know that was needed years ago!). Whatever reason they have called pluggable.php for I don&#8217;t know but it means that my plugin (or any other trying to declare a function first like this (it&#8217;s more common than you think!)) won&#8217;t function.</p>
<p>It&#8217;s such a simple solution but it works.. to fix you just need to rename my plugin directory to something else. WordPress naming conventions make calling a plugin anything starting with &#8216;WP&#8217; very trendy indeed. My plugins are all prefixed SB, my initial, for archiving more than anything else but the people who do the same with initials AA are laughing at us all right now I assure you (or not laughing but living in blissful ignorance!). Here&#8217;s the logic.. it&#8217;s really simple:</p>
<p>On any given page load WordPress will load it&#8217;s core files first and then look for plugins to bolt on to the system using the action/filter system. This is where the PHP files are initially &#8216;required&#8217;/'included&#8217; and individual balls (controlled by the plugin writers) set in motion. WordPress keeps a list of active plugins to call in the database in the wp_options table under an imaginatively named row called &#8216;active_plugins&#8217;. This is an alphabetically ordered list of plugins labelled by their location beneath the plugins directory (eg: <em>welcome-email-editor/sb_welcome_email_editor.php</em>). It will run from top to bottom including these files. This means there is a priority order for code defined only by the fact it has a name higher up the alphabet.</p>
<p>So to conclude the way to get your plugin run first to avoid conflicts with other plugins just put it in a directory called something beginning with a low alphabetical letter or special character. In my case I get a conflict every few months so it&#8217;s not worth changing but I am going to recommend that the next person to mention a conflict just renames their plugin folder from <em>welcome-email-editor</em> to <em>-welcome-email-editor</em> (note the leading hyphen). Job done!</p>
<p>I might add that changing the name of a plugin directory once a site is live isn&#8217;t a good idea on account of some plugins storing pathing information in the DB and WordPress itself storing the fact that plugin is active or not by it&#8217;s name in the directory tree. Put plainly if I change the name of my Welcome Email Editor plugin on my own site then it will deactivate itself and I shall need to reactivate it for it to continue working. Not a huge feat but try explaining that to normal user. Cue yet more support emails.</p>
<p>Hope this explains an issue for one or two of you. Perhaps plugin writers will learn not to call core PHP files directly in future to make my day run more smoothly&#8230; I doubt it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2012/01/wordpress-plugin-queue-jumping-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the WordPress Excerpt outside of The Loop</title>
		<link>http://www.sean-barton.co.uk/2011/11/getting-the-wordpress-excerpt-outside-of-the-loop/</link>
		<comments>http://www.sean-barton.co.uk/2011/11/getting-the-wordpress-excerpt-outside-of-the-loop/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 14:36:13 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Bug Fixes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=654</guid>
		<description><![CDATA[I have been working my way around this one for a few months now, never bothering to think about the best solution. There is not, in fact, a WordPress simple function to get the excerpt outside of the WordPress loop. Why would you want to do that you ask&#8230; Example: I have a plugin I have written to create a basic shopping cart and shop front. It makes use of a simple shortcode on a Page to generate the shop which is based on a custom post type called Products. The Loop is used on the main page itself to &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2011/11/getting-the-wordpress-excerpt-outside-of-the-loop/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been working my way around this one for a few months now, never bothering to think about the best solution. There is not, in fact, a WordPress simple function to get the excerpt outside of the WordPress loop. Why would you want to do that you ask&#8230;</p>
<p>Example:</p>
<p>I have a plugin I have written to create a basic shopping cart and shop front. It makes use of a simple shortcode on a Page to generate the shop which is based on a custom post type called Products. The Loop is used on the main page itself to generate the WordPress Page and subsequently process the shortcode. I loop through the products using a query_posts statement to bung the data into an array (for caching and manipulating so using a child Loop isn&#8217;t possible here) and then loop over it again later on. I want to show the Excerpt (which may or may not exist) on the shop front and the full description for my individual product pages.</p>
<p>So I initially thought of doing something like the following:</p>
<pre>&lt;?php
$product = get_page($product_id);
echo $product-&gt;post_excerpt;
?&gt;</pre>
<p>What this approach does wrong is returns nothing at all when the user hasn&#8217;t filled in an Excerpt for the product they entered. WordPress normally takes a selection of text from the main content, strips out any HTML and shortcodes and shows that instead.</p>
<p>Next option is this:</p>
<pre>&lt;?php
echo get_the_excerpt();
?&gt;</pre>
<p>What this does is prints the excerpt for the page which the shop front it hosted on (the parent page) because, as far as The Loop is concerned, the context of the page isn&#8217;t a shop front, it&#8217;s just a normal Page.</p>
<p>So why does this not work?</p>
<pre>&lt;?php
echo get_the_excerpt($product_id);
?&gt;</pre>
<p>Well some bright spark on a blog out in the ether thought it did however, regardless of what the argument for the function was initially, it no longer works as has been depracated (the argument that is).</p>
<p>So what&#8217;s the solution&#8230; well sadly it&#8217;s a custom function of your own. Luckily for you I have backtraced the code and writted my own little version of the above and it works a treat&#8230;</p>
<pre>&lt;?php
        function get_the_excerpt($id=false) {
            global $post;

            $old_post = $post;
            if ($id != $post-&gt;ID) {
                $post = get_page($id);
            }

            if (!$excerpt = trim($post-&gt;post_excerpt)) {
                $excerpt = $post-&gt;post_content;
                $excerpt = strip_shortcodes( $excerpt );
                $excerpt = apply_filters('the_content', $excerpt);
                $excerpt = str_replace(']]&gt;', ']]&amp;gt;', $excerpt);
                $excerpt = strip_tags($excerpt);
                $excerpt_length = apply_filters('excerpt_length', 55);
                $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');

                $words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
                if ( count($words) &gt; $excerpt_length ) {
                    array_pop($words);
                    $excerpt = implode(' ', $words);
                    $excerpt = $excerpt . $excerpt_more;
                } else {
                    $excerpt = implode(' ', $words);
                }
            }

            $post = $old_post;

            return $excerpt;
        }
?&gt;</pre>
<p>I have put mine in a class I used for my plugins these days as a helper function however just rename it (to avoid a naming conflict with it&#8217;s namesake) and call it from your plugin or theme as you would normally.</p>
<p>hope this helps someone out. Please let me know if anyone knows a better or simpler way. This works for me but I really wish there wasn&#8217;t such a monumental oversight by the WordPress guys on this one (other than creating sub loops which just feels wrong and inflexible to me)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2011/11/getting-the-wordpress-excerpt-outside-of-the-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get into a WordPress site without a login, just FTP</title>
		<link>http://www.sean-barton.co.uk/2011/08/how-to-get-into-a-wordpress-site-without-a-login-just-ftp/</link>
		<comments>http://www.sean-barton.co.uk/2011/08/how-to-get-into-a-wordpress-site-without-a-login-just-ftp/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 11:14:42 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=634</guid>
		<description><![CDATA[Ok interesting problem for you&#8230; your client gives you the FTP information for his server but has no idea what the admin password is for the WordPress site you are supposed to be working on is. Sounds a little odd but in the case I experienced the user account was an Editor role which is, in effect, useless if you want to play with plugins or users etc&#8230; Here&#8217;s how I got in&#8230; WordPress stores it&#8217;s passwords as hashes in the database for security purposes. Annoying if you are trying to find out other people&#8217;s passwords though. Luckily the hashinh &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2011/08/how-to-get-into-a-wordpress-site-without-a-login-just-ftp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ok interesting problem for you&#8230; your client gives you the FTP information for his server but has no idea what the admin password is for the WordPress site you are supposed to be working on is. Sounds a little odd but in the case I experienced the user account was an Editor role which is, in effect, useless if you want to play with plugins or users etc&#8230;</p>
<p><strong>Here&#8217;s how I got in&#8230;</strong></p>
<p>WordPress stores it&#8217;s passwords as hashes in the database for security purposes. Annoying if you are trying to find out other people&#8217;s passwords though. Luckily the hashinh algorithm is standard md5 across any site you use. I have several WordPress sites of my own set up so I opened up Navicat and got the password hash for a site I know the password to.</p>
<p>I then opened up the functions.php file for the theme I knew was active on the clients server and added the following code:</p>
<pre>global $wpdb;
$sql = 'SELECT * FROM ' . $wpdb-&gt;users;
echo '&lt;pre&gt;';
print_r($wpdb-&gt;get_results($sql));
echo '&lt;/pre&gt;';

$sql = 'UPDATE ' . $wpdb-&gt;users . ' SET user_pass = "$P$Ba8do3KsWiaThA80UbfHygumoUFu3i1" WHERE ID = 1';
$wpdb-&gt;query($sql);</pre>
<p>Idiot proof right! You need the first query to give you the name of the admin account. This is the one with the ID of 1 and the original hash to put back once you have your own user. The second part updates that record with your own password hash. Only run the page the once and make sure to write down the old password hash because you will lose it on the second refresh otherwise.</p>
<p>Once in I simply created my own administrator user and then replaced the hash in the second query for the original, ran it, removed the code and I was done.</p>
<p>It&#8217;s an odd situation when you would need to do this but the same method works for most site authentication systems assuming they aren&#8217;t doing anything really clever with the hashes&#8230; in my experience, they don&#8217;t!</p>
<p><em>Note: if you were wondering what $P$Ba8do3KsWiaThA80UbfHygumoUFu3i1 means when not hashed&#8230;. it&#8217;s &#8216;sausages&#8217; <img src='http://www.sean-barton.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2011/08/how-to-get-into-a-wordpress-site-without-a-login-just-ftp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple custom post type features for WordPress</title>
		<link>http://www.sean-barton.co.uk/2011/07/simple-custom-post-type-features-for-wordpress/</link>
		<comments>http://www.sean-barton.co.uk/2011/07/simple-custom-post-type-features-for-wordpress/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 12:50:24 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=601</guid>
		<description><![CDATA[I have been using custom post types in WordPress for a long time now&#8230;. In fact each new theme or plugin I write I tend to integrate a custom post type and some supplementary meta boxes here and there. If you have no idea what i&#8217;m talking about then this article probably isn&#8217;t for you&#8230; however read on and I shall explain briefly. Custom post types are wonderful for parts of sites that don&#8217;t generally fit into the standard Post or Page model. For instance WP Ecommerce (the most popular WP shopping cart) has just started using custom post types &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2011/07/simple-custom-post-type-features-for-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-609" title="WordPress-Introduction-icon_big-en" src="http://www.sean-barton.co.uk/wp-content/uploads/2011/07/WordPress-Introduction-icon_big-en-150x150.png" alt="" width="150" height="150" />I have been using custom post types in WordPress for a long time now&#8230;. In fact each new theme or plugin I write I tend to integrate a custom post type and some supplementary meta boxes here and there. If you have no idea what i&#8217;m talking about then this article probably isn&#8217;t for you&#8230; however read on and I shall explain briefly.</p>
<p>Custom post types are wonderful for parts of sites that don&#8217;t generally fit into the standard Post or Page model. For instance WP Ecommerce (the most popular WP shopping cart) has just started using custom post types for storing their products&#8230; you will get the idea, products being a custom post type. If I say that they are a way of storing things in WordPress that can, if needed, provide a way of administering these objects as if they were a page like any other.</p>
<p>Adding them yourself requires some code and adding the fields that will appear on the page will require some more. This isn&#8217;t what I want to go over right now as there is an easier way. To get an idea of what I mean, see the following screenshots&#8230;</p>
<div id="attachment_602" class="wp-caption alignleft" style="width: 160px"><a rel="lightbox" href="http://www.sean-barton.co.uk/wp-content/uploads/2011/07/Screen-shot-2011-07-15-at-13.24.28.png"><img class="size-thumbnail wp-image-602" title="Screen shot 2011-07-15 at 13.24.28" src="http://www.sean-barton.co.uk/wp-content/uploads/2011/07/Screen-shot-2011-07-15-at-13.24.28-150x150.png" alt="" width="150" height="150" /></a><p class="wp-caption-text">Note the bottom three, they are custom post types</p></div>
<div id="attachment_603" class="wp-caption alignleft" style="width: 160px"><a rel="lightbox" href="http://www.sean-barton.co.uk/wp-content/uploads/2011/07/Screen-shot-2011-07-15-at-13.25.10.png"><img class="size-thumbnail wp-image-603" title="Screen shot 2011-07-15 at 13.25.10" src="http://www.sean-barton.co.uk/wp-content/uploads/2011/07/Screen-shot-2011-07-15-at-13.25.10-150x150.png" alt="" width="150" height="150" /></a><p class="wp-caption-text">This admin interface is generated for you with 0 effort.</p></div>
<p>&#8220;Products&#8221; is generated by WP Ecommerce and my theme added &#8220;FAQs&#8221; and &#8220;Photography&#8221;. The second screenshot shows the admin interface, similar to the post/page editor, which is generated and the meta boxes which can be added very easily indeed to make it appear that way. The way that these can be added without writing any code would be to use one of the &#8216;More&#8217; plugins&#8230;. These are More Fields, More Types and More Taxonomies&#8230; all freely available WordPress plugins although I tend not to use them these days (I write them into my themes instead). Take a look though.</p>
<p>This article was really to outline what you do with the data within these types in the real world. Of course storing the data is easy, using it requires some imagination really. The post type items are stored in the wp_posts table and the fields you add as meta data are stored in wp_usermeta. You can easily retrieve the information using standard WordPress functions.</p>
<p>The following function can be used to get all of the photography items and store them in an Array of Objects for looping and output any way you see fit&#8230;</p>
<pre>function get_custom_post_type_items($custom_post_type) {
	$args = array(
	'post_type' =&gt; $custom_post_type,
	'post_status' =&gt; 'publish',
	'posts_per_page' =&gt;-1,
	'orderby' =&gt; 'post_date',
	'order' =&gt; 'DESC'
	);

	$posts = new WP_Query($args);
	$return = array();

	if ($posts-&gt;have_posts()) {
		while ($posts-&gt;have_posts()) {
			$posts-&gt;the_post();

			$post_id = get_the_ID();

			$sub_post = new stdClass();
			$sub_post-&gt;post_id = $post_id;
			$sub_post-&gt;title = get_the_title();
			$sub_post-&gt;permalink = get_permalink($post_id);
			$sub_post-&gt;content = wpautop(get_the_content());
			$sub_post-&gt;meta_data = get_post_meta($post_id, 'meta_data_name, true);

			$return[] = $sub_post;
		}
	}

	wp_reset_query();

	return $return;
}</pre>
<p>You can use this function in your functions.php file in your theme to be called by a page template or a shortcode if you add one to return the items you have added as custom post types. I have added a single meta data item called meta_data in each row which gets a custom field from the custom post type item called meta_data_name. In my Photography example I would just have more lines like this to get the various items from my custom meta box</p>
<pre>$sub_post-&gt;png_image = get_post_meta($post_id, 'png_image_url, true);</pre>
<p>Another good example use of this function would be for a featured items slider that you often see at the top of websites. One or more pages might have a portfolio item slider or a rotating banner or something. In that case you would call my function from your header.php file then loop through it outputting the appropriate HTML per line before using something like a jQuery call to construct the slider.</p>
<p>When you understand the applications for custom post types you might be finding yourself using them in more and more creative ways. I wrote a custom meta box a while back to link custom post type items to each other across different types. This was to allow staff member types to be linked to team and office types and so on. Then using this association you can output something like a dynamic organisational chart using a shortcode or a custom page template without having to hard code a thing.</p>
<p>This is a thinker, I imagine, for some people. Get in touch with me if you want any help putting these custom post types in place and utilising them on your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2011/07/simple-custom-post-type-features-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Want a website? Basic details on cost and what you are likely to be asked for&#8230;</title>
		<link>http://www.sean-barton.co.uk/2011/07/want-a-website-basic-details-on-cost-and-what-you-are-likely-to-be-asked-for/</link>
		<comments>http://www.sean-barton.co.uk/2011/07/want-a-website-basic-details-on-cost-and-what-you-are-likely-to-be-asked-for/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 22:32:01 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[Shameless Plugs]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[get a website]]></category>
		<category><![CDATA[website advice]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=598</guid>
		<description><![CDATA[A lot of my clients seem to think, at least initially, that having a website built is a case of asking someone like me to write one and then their involvement stops. That is not the case as you are about to find out. This isn&#8217;t a rant or attack on people who don&#8217;t know the specifics of the web but hopefully will serve as a guide to those people or give other people like me a checklist to refine and give their clients&#8230; First things first&#8230; Costs. It doesn&#8217;t cost the earth to have a website written. A normal &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2011/07/want-a-website-basic-details-on-cost-and-what-you-are-likely-to-be-asked-for/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-599" title="Website Construction" src="http://www.sean-barton.co.uk/wp-content/uploads/2011/07/web_construction-150x150.jpg" alt="" width="150" height="150" />A lot of my clients seem to think, at least initially, that having a website built is a case of asking someone like me to write one and then their involvement stops. That is not the case as you are about to find out. This isn&#8217;t a rant or attack on people who don&#8217;t know the specifics of the web but hopefully will serve as a guide to those people or give other people like me a checklist to refine and give their clients&#8230;</p>
<p><em>First things first&#8230; Costs.</em></p>
<p>It doesn&#8217;t cost the earth to have a website written. A normal company is likely to want a presence on the net and that&#8217;s it. No need for huge fancy sites to be optimised to within an inch of their life and no need to even have a graphic designer involved. Of course you can do, and generally end up with a better site but if you want to keep things simple then it&#8217;s not necessary.</p>
<p>There are only really two ongoing costs for a website&#8230; domain name(s) and website hosting.</p>
<p><em>Domain Names</em></p>
<p>A domain name is very cheap indeed although costs do vary. In the past I have used a few registraars and people always have their favourites. I use Europe Registry for this site but have just registered <a title="Narrowboating Articles Website" href="http://www.letsboat.co.uk" target="_blank">www.letsboat.co.uk</a> with <a title="Web hosting with 123-reg" href="http://goo.gl/hrEE6" target="_blank">123-reg</a> (aff link) for a grand total of £7 for two years.</p>
<p><em>Web Hosting</em></p>
<p>Many website developers such as myself will offer to host the site for you at £X per year. This is a good idea if you want a lot of support but ultimately it&#8217;s cheaper to do it yourself and pay a developer when (if) things go wrong. This site is hosted with <a title="Website host" href="http://www.imountain.com" target="_blank">imountain</a> however I wouldn&#8217;t recommend them at all. It costs me $10 per month but I find it very slow here in the UK. I tend to recommend <a title="Hosting with Hostgator" href="http://goo.gl/QKHpT" target="_blank">Hostgator</a> (aff link) to my clients.  All you need for your own website is their most basic package although I would recommend their Baby plan in case you want to host more than one site using the same account. you can pay monthly with most hosts although you only usually get the quoted prices if you pay for two or three years up front. Depending on your financial situation this might be worth doing. If you go to <a title="Hostgator.com Affiliate Link" href="http://goo.gl/QKHpT" target="_blank">hostgator.com</a> and use <strong>tortoise25</strong> as the coupon code you will get 25% off the quoted price if it helps.</p>
<p><em>Website Development</em></p>
<p>No one, if they can help it, writes sites in pure code any more. They are a nightmare to maintain and generally not very good. Also, as the client, you end up paying for a developer to make the smallest change. This is where WordPress comes in. WordPress, a content management system (CMS), allows you and developers to write sites (like this one in fact) quite quickly and with a massive range of free themes and plugins to make sites do whatever you want them to. Galleries, shops, video players, etc&#8230; All doable without much more than a few simple steps.</p>
<p>Installing WordPress requires you to get a PHP enabled server, set up a MySQL database, FTP up the WordPress files found at WordPress.org, apply the theme, add some plugins and write the content in. Sounds like a lot but when you do it for a living it doesn&#8217;t take long to get something up there. However it&#8217;s kind of like car maintenance.. you think you can service it yourself and you know that, in principle, replacing a few engine consumables is an easy job and takes a mechanic only a couple of hours. Then you start the job and it takes two days and never does run right after that. See the parallel there? <img src='http://www.sean-barton.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>That&#8217;s it&#8230;. you never have to pay for content updates and you can  always contact me for advice/help. If you hadn&#8217;t noticed, I&#8217;m a bit of a WordPress enthusiast. But then why not when WordPress is used for a huge number of sites on the internet (50,000,000 I think was the last count I read).</p>
<p><em>What do you need to provide to a Website Developer?</em></p>
<p>Simple enough question to ask, hard question to answer really. Here is a very basic list&#8230;</p>
<ul>
<li>Content</li>
<li>Look and feel</li>
<li>Gather resources to use</li>
</ul>
<p>And then for any site with an ecommerce aspect:</p>
<ul>
<li>Products</li>
<li>Payment processor (Paypal, Clickbank, Sagepay, etc&#8230;)</li>
<li>Gather resources for download or delivery</li>
</ul>
<p><em>Let me expand on these&#8230;</em></p>
<p>Content is self explanatory. I  recommend firstly thinking about how many pages you want on the site and  then jotting down, in something like Word, the content for each page.  Images to compliment text is always a nice addition but can be done  later. Additionally with a domain and a  site you might want to let people get in touch with you. Have a think  about what phone numbers (if any) and email addresses you want public or  if you just want a contact form.</p>
<p>Look and feel is something that will definitely need to be expanded on. If you have a look at a few themes around the internet. There are  literally thousands of them out there, loads free and others premium.  Either is ok and neither better than the other. WordPress has <a title="Wordpress theme directory" href="http://wordpress.org/extend/themes/" target="_blank">it&#8217;s own showcase</a> of free themes (required to be free to be in the list!). Someone like myself will firstly ask if you want a graphic designer involved, at which stage this process will be escalated to another level of cost and complexity. However, if you want something basic then a free theme will do. There are a large number of &#8216;framework&#8217; based themes for free out there which allow people to edit their theme without touching the code. They tend to be very basic but might be a good starter. Otherwise there are even more standard themes about which can be modified to suit if need be. I normally recommend that people give up to three themes from the directory they like and then a new theme can be made which incorporates the better features of each.</p>
<p>Gathering resources is really just a cursory note for you to gather any  images or logos (your company logo for example) in digital form to be added to the site. They need to be as high a quality as you can find.  Images like logos should really be in JPG, PNG or GIF format and be  bigger than needed so they can be trimmed to fit for the site. You can make  images smaller and retain quality but not make them bigger.</p>
<p>Ecommerce aspects really are similar&#8230; Products is just something,  as before, for you to think about. The descriptions for the products,  the pricing, images and ways of getting hold of them (postage, pdf,  etc..)</p>
<p>Payment processor is what we call the way in which people are asked to  pay for their items. Normally Paypal is the standard for small sites.  People tend to have accounts via eBay these days anyway. Other types of  processor are available but tend to incur monthly costs (£20/month I  think for Sagepay). Paypal is the easiest if you want to keep ongoing costs down. The requirement to sell  is that you have a premier or business account. To do it you just need  to login and look at your account settings then jump the hoops to update  your account. This simply involves linking a bank account to you Paypal  account (takes a few days, best done in advance of being needed).  Nothing official otherwise needed.</p>
<p>Gathering resources is, again, just putting together the images and  the content for the products. There are several shopping carts for use for  downloads and ecommerce within WordPress.</p>
<p><em>SEO</em></p>
<p>Perhaps the buzzword of the net these days. I&#8217;ve not yet met someone that hasn&#8217;t heard the acronym although often people don&#8217;t know what it means&#8230; only that they want it. Plugins exist for free for WordPress to allow you to add your site to Google and other search engines and to allow you to compliment your content with the right sort of data to get you noticed. There are quite a few guides on the internet to help you through this.</p>
<p><em>Summary</em></p>
<p>So what was the point of all that then? Well&#8230; hopefully now you shall know about the sorts of things you are likely to be asked for when wanting a website and will be prepared for your initial conversation with website developers if that&#8217;s the direction you want to go.</p>
<p>By all means get in touch with me to go over any project you have in mind or even just to get an idea of how much it would cost for me to do it all for you. Take a look at some of the sites I have done in the past on my <a title="Sean's Portfolio" href="http://www.sean-barton.co.uk/portfolio/" target="_blank">Portfolio</a> page or get in touch using either of my <a title="Get in touch with Sean" href="http://www.sean-barton.co.uk/contact-me/enquiry/" target="_blank">contact</a> or <a title="Sean's get a quote form" href="http://www.sean-barton.co.uk/hire-me/" target="_blank">get a quote</a> forms.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2011/07/want-a-website-basic-details-on-cost-and-what-you-are-likely-to-be-asked-for/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP source code protection &#8211; the basics</title>
		<link>http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/</link>
		<comments>http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 18:33:03 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=540</guid>
		<description><![CDATA[If you have ever sold or considered selling your code/application you would most likely have thought, if only briefly, about stopping people from buying a copy of your code then passing it to their ten friends (disclaimer: not all people have ten friends! some have more (or less!)) for free. &#8216;Why not add a product key?&#8217; you ask! Well yes a product key would do the job and avert the efforts of a portion of these people but obviously when using an interpreted/scripted language such as PHP they will be able to open up your source code, remove any license &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-544" title="Padlock" src="http://www.sean-barton.co.uk/wp-content/uploads/2011/04/Padlock-300x284.jpg" alt="" width="180" height="170" />If you have ever sold or considered selling your code/application you would most likely have thought, if only briefly, about stopping people from buying a copy of your code then passing it to their ten friends (disclaimer: not all people have ten friends! some have more (or less!)) for free.</p>
<p><strong>&#8216;Why not add a product key?&#8217; you ask!</strong></p>
<p>Well yes a product key would do the job and avert the efforts of a portion of these people but obviously when using an interpreted/scripted language such as PHP they will be able to open up your source code, remove any license  checking code and then pass the &#8216;cracked&#8217; version around as before. Generally it&#8217;s not hard to find this sort of code&#8230; simply look for any filenames which hint at &#8216;licensing&#8217; or &#8216;auth&#8217;, open them up (usually very small files) and put a &#8216;return true;&#8217; at the start of the key checking method.  As I said this method stops a large portion of people from passing it around so it&#8217;s still worth doing.</p>
<p><strong>What about a &#8216;call home&#8217; script?</strong></p>
<p>Same story here I&#8217;m afraid but more convenient for the seller (and you can get some lovely stats on the people using your code). A Call Home script is simply a piece of code that runs on the client site (per page load? per admin page load? every day on a CRON job?) and in effect sends a request back to a central server run by the code seller (you?) to simply authenticate sites. If, for example, example.com buys a script from <em>my_premiumscripts.com</em> then installs it on their server&#8230; Every so often the example.com server will call the <em>my_premiumscripts.com</em> server and have the following conversation:</p>
<p><em>example.com (e)</em>: Dude?<br />
<em>my_premiumscripts.com (m)</em>: Dude?<br />
<em>e</em>: So&#8230; I&#8217;m just checking in with you, everything ok?<br />
<em>m</em>: Ah great stuff, yes I see you purchased a copy of my code. Feel free to carry on using it.<br />
<em>e</em>: Brilliant!<br />
<em>m</em>: Indeed. don&#8217;t forget to check in with me tomorrow though.<br />
<em>e</em>: Ok bye!</p>
<p>Or they could say this:</p>
<p><em>example_dotcomsmate.com (e)</em>: Dude?<br />
<em>my_premiumscripts.com</em><em> (m)</em>: Dude?<br />
<em>e</em>: So&#8230; I&#8217;m just checking in with you, everything ok?<br />
<em>m</em>: Who are you again?<br />
<em>e</em>: I&#8217;m a new site you don&#8217;t know about. I got your script from a friend (torrent? friend? unauthorised reseller?)<br />
<em>m</em>: Oh ok, that&#8217;s fine with me but you have to send me some money first before you can use the software.<br />
<em>e</em>: What? Hey I just want to have a look at it for a few days (years)<br />
m: Nope sorry, I am going to deactivate the software on your site now. Bye!<br />
e: Oh ok, bye!</p>
<p>Ok I jazzed up the conversation a bit but you get the idea. Call home scripts work really well from a protection point of view but have one really major drawback&#8230; they require you, as the seller, to have a 100% uptime server and it requires either the client server or the clients users to each initiate a request to that server. This means that both your server is going to get a lot of, what can only be described as, logging traffic (useless to everyone really) and the clients (servers or client machines) are going to get a worse (slower) user experience because of it. That and if you ever decide to move server or domain for the script then there is a lot of admin to do.</p>
<p>Either way there is the potential for you lose out on potential lovely cash. What we need is to be able to use the product key method with a way of stopping people from getting at the source code. There are a few ways to do this, some more awkward than others (both for the purchaser and the developer). The two worth mentioning are:</p>
<p><strong>Code Encryption</strong></p>
<p>This is the daddy of code protection. If your code is protected by an encryption algorithm then people are unable to look at the source code no matter how resourceful. The real downside of this is that you have to force your users to install additional server software before your code will run on their server. No simple FTP it up and start using it type system; this method is likely to involve your server host and a support ticket or two. An example of this would be any system that uses Ioncube Loader which, I understand to be, the same sort of thing.</p>
<p><strong>Code Obfuscation</strong></p>
<p>This is the lighter and more manageable version of the above. Whenever you look at an obfuscated file it will appear jibberish to the reader. PHP can interpret it because it doesn&#8217;t care whether a variable or function/method has a name which is human readable or not. Obfuscation works by removing all whitespace, renaming functions and variables and swapping out ascii text for a different characterset/encoding which is not immediately obvious to a novice that it&#8217;s text. Often these scripts make use of nested loops, dummy methods and evaluated code (code as a string which has then had the eval() function passed over it. Base64 encoding is popular but very easy to spot and decode to it&#8217;s use is on the decline. No additional software is required to run obfuscated code, it&#8217;s just a pain when there is an error in the code and the developer, for example, is on holiday for the next month! The downside of this for the developer is that it can be decoded and reverted to something resembling it&#8217;s original form (minus original function and variable names) by simply working backwards. Well&#8230; it&#8217;s not simple at all but is doable! Many virus script writers use this method of hiding a scripts intention. I have had to decode a few myself and it&#8217;s not fun.</p>
<p><strong>Recommendations</strong></p>
<p>My only recommendation is going to be to use neither and just go with a simple product key. Yes you are going to get taken for a ride by some people who want to redistribute it amongst their friends but think about it&#8230; they can&#8217;t get any updates from you, no support and if their source of the code disappears then they might even come and buy from you in the first place.</p>
<p>The key is to constantly be working on your scripts/applications. Don&#8217;t settle on a single version for too long, encourage a good community around the work and most importantly don&#8217;t rip people off in the first place&#8230; if the price is reasonable then people will happily pay it. A cheaper price is also a nice reason to offer sightly less involved support. It&#8217;s also a possible avenue of further income, premium support etc..</p>
<p>The real issue with any form of code protection is that updates and critical fixes won&#8217;t work without the original developer putting a new package together and, often, the entire fileset being replaced. If something goes wrong and the developer is not available then the job can not be outsourced which causes more issues. This is why I would always recommend you stand behind a well written Terms and Conditions document which must be agreed before the software can be used. Generally a block in the code is a challenge to be overcome, a legal document that requires signing and makes you liable is not!</p>
<p>Thanks for reading!</p>
<p><em>nb: example.com, example_dotcomsmate.com and </em><em>my_premiumscripts.com</em><em> are fabricated and although they might exist have no relation to the content in this article.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Recursive PHP function for finding a top level parent post</title>
		<link>http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/</link>
		<comments>http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 23:16:14 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=449</guid>
		<description><![CDATA[So&#8230; the name says it all doesn&#8217;t it! Here&#8217;s the story.. I wanted to apply different sidebar widget areas in Wordress for different pages. One of the sites I am working on has three top level pages which will form three distinct sections of the site. I decided that it would be good to show different sets of widgets within these sections and therefore had to concoct a way to determine from any page it&#8217;s top level parent page. The function below simply returns true or false if the first argument is a child of the second. It also returns &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So&#8230; the name says it all doesn&#8217;t it! Here&#8217;s the story.. I wanted to apply different sidebar widget areas in Wordress for different pages.</p>
<p>One of the sites I am working on has three top level pages which will form three distinct sections of the site. I decided that it would be good to show different sets of widgets within these sections and therefore had to concoct a way to determine from any page it&#8217;s top level parent page. The function below simply returns true or false if the first argument is a child of the second. It also returns true if the first argument is the same as the second.</p>
<p><strong>The Function</strong></p>
<pre>function page_has_parent($current_page, $target_parent=0) {
	global $wpdb;

	$return = false;

	if ($current_page == $target_parent) {
		$return = true;
	} else {
		$sql = 'SELECT post_parent
			FROM ' . $wpdb-&gt;posts . '
			WHERE ID = ' . $current_page;
		if ($parent = $wpdb-&gt;get_var($sql)) {
			if ($parent == $target_parent) {
				$return = true;
			} else if ($parent) {
				$return = page_has_parent($parent, $target_parent);
			}
		}
	}

	return $return;
}</pre>
<p><strong>The Usage</strong></p>
<p>The following is a WordPress example of showing one sidebar or the other based on page</p>
<pre>$this_page = get_the_ID();
if (page_has_parent($this_page, 7)) {
	dynamic_sidebar('Sidebar2');
} else if (page_has_parent($this_page, 11)) {
	dynamic_sidebar('Sidebar2');
} else ....</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SB Author Comments: Author Commenting plugin for WordPress</title>
		<link>http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/</link>
		<comments>http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 19:27:22 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[comment author]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=422</guid>
		<description><![CDATA[To my knowledge it&#8217;s not possible to comment on an author in WordPress. &#8220;Why would you want to do that?&#8221; you ask&#8230; Well for example a client of mine is running a classifieds site using the Classipress theme. The site uses classifieds as jobs for people to do and the people posting and signing up to the site are tradesmen. Comments, in this case, can be used as a feedback system and therefore are a valuable addition. The wp_comments table doesn&#8217;t have support or scope to store comments with an associated user (as opposed to post). At this juncture I &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To my knowledge it&#8217;s not possible to comment on an author in WordPress. &#8220;Why would you want to do that?&#8221; you ask&#8230; Well for example a client of mine is running a classifieds site using the Classipress theme. The site uses classifieds as jobs for people to do and the people posting and signing up to the site are tradesmen. Comments, in this case, can be used as a feedback system and therefore are a valuable addition.</p>
<p>The wp_comments table doesn&#8217;t have support or scope to store comments with an associated user (as opposed to post). At this juncture I would have inserted a null (or 0) value into the post_id column and added a row into the wp_commentmeta table with the user ID it refers to. However, I didn&#8217;t write the core code for the project so I simply updated a neat little system written by <em>Dan Wellman</em>. Dan&#8217;s system is pretty good and uses AJAX and JSON to add comments to a new database table with two fields (author and comment). It was what I would call &#8216;a good start&#8217; as DB details were required in a number of different files and the database had room for improvement. I have a few more plans for the code but for now have changed a couple of things and bundled it into a WordPress plugin for you.</p>
<p>In my version the database table is created for you, it has several more fields including a primary key (!), timestamps and room for additional information (not currently utilised) to be stored. The WordPress database class is used now so no duplication of the connection details is necessary.</p>
<p>Take a look at the plugin and comments and suggestions for additions are very welcome.</p>
<p><strong>Download</strong><br />
<a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=17" title="Version 1 downloaded 218 times" >SB Author Comments (1.84 kB)</a></p>
<p><strong>Usage</strong><br />
Upload and activate the plugin as normal. Then add the following code to your author.php theme template making sure to edit the $author_id variable as appropriate.</p>
<pre>&lt;?php
if (function_exists('sb_ac_comment_form')) {
echo sb_ac_comment_form($author_id);
}
?&gt;</pre>
<p><strong>Credit</strong><br />
Once again credit goes to <em>Dan Wellman</em> who detailed the integration into his site on his <a href="http://net.tutsplus.com/tutorials/php/asynchronous-comments-with-jquery-and-json/" target="_blank">blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to convert your site to WordPress</title>
		<link>http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/</link>
		<comments>http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 12:00:25 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Wordpress migration]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=413</guid>
		<description><![CDATA[I recently had a conversation with someone who had decided to come to WordPress to take advantage of a plugin or two and wanted to know how to get an existing site into the correct theme structure as required. It took a lengthy email or two to explain but it struck me that lots of people must be asking the same questions over and over. So in this post i shall try to explain how to get a theme together, or rather where to start So&#8230; first, a bit of logic Logically speaking a standard layout web page can be &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-416" title="Wordpress Logo" src="http://www.sean-barton.co.uk/wp-content/uploads/2010/03/23-wordpress_logo.png" alt="Wordpress Logo" width="154" height="154" />I recently had a conversation with someone who had decided to come to WordPress to take advantage of a plugin or two and wanted to know how to get an existing site into the correct theme structure as required. It took a lengthy email or two to explain but it struck me that lots of people must be asking the same questions over and over. So in this post i shall try to explain how to get a theme together, or rather where to start</p>
<p><em>So&#8230; first, a bit of logic</em></p>
<p>Logically speaking a standard layout web page can be split into four distinct areas as follows:</p>
<ul>
<li>Header</li>
<li>Footer</li>
<li>Sidebar(s)</li>
<li>Content</li>
</ul>
<p>And as such WordPress uses different theme files to render the appropriate sections. We need to split our HTML page into those different files. There are, however, lines of code that WordPress needs you to put into each of these files and so tbe best way todo this without missing anything is to recycle another theme. So&#8230; go to your WordPress install and visit <em>/wp-content/themes/</em> and&#8230;</p>
<ol>
<li>Duplicate the directory called &#8216;<em>default</em>&#8216;</li>
<li>Open style.css in a text editor and edit the name of the theme and any other information you feel like</li>
<li>Either remove or replace <em>screenshot.jpg</em> from the theme directory so it looks different in the theme menu</li>
</ol>
<p>That&#8217;s it, you now have a skeleton to work from and it&#8217;s time to make it look like your site. Let&#8217;s assume you have a simple brochureware site and, therefore, don&#8217;t need any blog type pages. Largely these sites have a standard consistent layout on each page (often except the home page but that difference is for another tutorial) and WordPress uses this consistency to slot in the appropriate information for each page. We do this by&#8230;</p>
<ol>
<li>Choose a short yet typical page from your site and view the HTML source</li>
<li>Open 4 separate text files from the new theme directory in your favourite text editor. They are: <em>header.php, footer.php, sidebar.php and page.php</em></li>
<li>From the HTML source take the top section of code (usually as far as the content and sidebar code inclusive of a menu assuming you are using a top horizontal bar navigation) and place it into <em>header.php</em> making sure to preserve the obvious dynamic sections of code (anything between <em>&lt;?php</em> and <em>?&gt;</em> can be assumed to be dynamic)</li>
<li>Do the same with the footer into<em> footer.php</em> (the section below the content and sidebar that often contains SEO links and copyright notices)</li>
<li>The remaining block should contain the content and sidebar code&#8230; simply cut out the sidebar code into <em>sidebar.php</em></li>
<li>Finally split the content code into the bit before the text and the bit after the text (ie: layout code stripping out the text itself). Then paste these sections around the &#8216;while&#8217; loop within <em>page.php</em>.</li>
<li>(optional) copy your stylesheet into style.css making sure to preserve the comment at the top of the file as this is used by WordPress to define the theme and without which will not pick up any of the code.</li>
</ol>
<p>Step 6 will likely be the most difficult to do as there are three or four important lines of PHP code in there. Firstly the line that reads &lt;?php get_header(); ?&gt; is the code that calls header.php. Likewise &lt;?php get_footer(); ?&gt; and &lt;?php get_sidebar(); ?&gt; call their appropriate namesakes. Make sure that they are in the correct logical positions for the page to render in the right order.</p>
<p><strong>The Loop</strong></p>
<p>The hardest section is what is called &#8216;the loop&#8217; by WordPress bods. This is the section of code that shows the post(s) from the database relative to the page you are looking at. The Loop often falls into the following form:</p>
<pre>&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
 &lt;div id="post-&lt;?php the_ID(); ?&gt;"&gt;
 &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
 &lt;div&gt;
 &lt;?php the_content('&lt;p&gt;Read the rest of this page &amp;raquo;&lt;/p&gt;'); ?&gt;

 &lt;?php wp_link_pages(array('before' =&gt; '&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; ', 'after' =&gt; '&lt;/p&gt;', 'next_or_number' =&gt; 'number')); ?&gt;

 &lt;/div&gt;
 &lt;/div&gt;
 &lt;?php endwhile; endif; ?&gt;</pre>
<p>You shouldn&#8217;t really need to change any of the code itself but you might need to edit the encapsulating HTML to make your styles fit in. For example if your page titles are not in H2 tags then you need to change it to suit etc etc&#8230;</p>
<p><strong>Testing it!</strong></p>
<p>This will always be a case of trial and error until you know what you are doing so don&#8217;t worry if it all goes pear shaped. That&#8217;s what the undo button is for!</p>
<p>To test that your theme is working properly then you need to visit your sites back end at <em>/wp-admin</em> and click the link on the left hand side called &#8216;<em>appearance</em>&#8216;. The themes page will appear and to activate your theme you simply find it in the list and click &#8216;activate&#8217;. Then view the front end of the site and see what it looks like.</p>
<p>At this stage you might be confused because the home page looks different to the rest of the site. This is because, by default, WordPress uses the <em>index.php</em> file from your theme directory to generate the home page. To change this visit the <em>settings -&gt; reading</em> page from the left menu and use the dropdown box to choose an appropriate page to be used for the home page.</p>
<p><strong>What&#8217;s next?</strong></p>
<p>Ok so your theme looks like it did before you spent hours making the them for the WordPress site&#8230; why on earth are we using WordPress at all you ask! Well if you were to create a new page for your old site then you would have to duplicate an HTML file, trawl through code (or look at Dreamweaver or another WYSIWYG) to find the sections to replace before uploading to your site and updating the links in the various menus as appropriate. With WordPress you just add a &#8216;<em>page</em>&#8216; using the nice admin system and it&#8217;s all done for you.</p>
<p>I always tell my clients to go and have a look at the WordPress plugins directory for ideas and things to ad to their site. A word of warning though, some plugins conflict with others and too many plugins might slow your site down considerably. Over time you will get used to a core few you know and trust.</p>
<p><em>Feel free to ask me any questions about WordPress, PHP or other and hopefully I will be able to help you decide what&#8217;s the best direction for your site to take. Expect a lecture about how good WordPress is though!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 8/56 queries in 0.180 seconds using disk
Object Caching 796/890 objects using disk

Served from: www.sean-barton.co.uk @ 2012-02-05 14:14:56 -->
