<?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>36Flavours.com &#187; PHP</title>
	<atom:link href="http://36flavours.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://36flavours.com</link>
	<description>A taste of something different...</description>
	<lastBuildDate>Mon, 19 Apr 2010 20:01:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Outputting JSON with Zend Framework</title>
		<link>http://36flavours.com/2010/04/outputting-json-with-zend-framework/</link>
		<comments>http://36flavours.com/2010/04/outputting-json-with-zend-framework/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 20:01:53 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=705</guid>
		<description><![CDATA[Today I was looking for a quick solution to outputting a response in JSON format from within one of my existing Zend_Controller actions that could be both requested and parsed using one of the jQuery Ajax methods. The easiest method I could find was to use something similar to the following which first detects whether [...]]]></description>
			<content:encoded><![CDATA[<p class="first">Today I was looking for a quick solution to outputting a response in JSON format from within one of my existing Zend_Controller actions that could be both requested and parsed using one of the <a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery Ajax</a> methods.</p>
<p>The easiest method I could find was to use something similar to the following which first detects whether or not an XHTTP request has taken place, then outputs the response in plain text format.<span id="more-705"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">isXmlHttpRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'author'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Steve'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'categories'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'PHP'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Zend'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'JavaScript'</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonData</span> <span style="color: #339933;">=</span> Zend_Json<span style="color: #339933;">::</span><span style="color: #004000;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text/html'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBody</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$jsonData</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will output only the encoded array (similar to that below) without including the page template.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;author&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Steve&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;categories&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;PHP&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;Zend&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>It is essential that you exit the script after outputting the JSON, otherwise your page template will be rendered as well as outputting the encoded array and therefore removing the ability for it to be parsed correctly.</p>
<p>You should be aware that the <a href="http://framework.zend.com/manual/en/zend.controller.request.html" target="_blank">isXmlHttpRequest</a> method checks for an HTTP request header named X-Requested-With with the value &#8216;XMLHttpRequest&#8217; and therefore may not work with all JavaScript libraries.</p>
<p>It does however work as expected with Prototype, Scriptaculous, Yahoo! UI Library, jQuery and MochiKit.</p>
<p>There are many alternative methods that could be used instead of this one, it&#8217;s just that I found this one to be the quickest and most simplistic method.</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2010/04/outputting-json-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress exclude categories from homepage</title>
		<link>http://36flavours.com/2010/01/wordpress-exclude-categories-from-homepage/</link>
		<comments>http://36flavours.com/2010/01/wordpress-exclude-categories-from-homepage/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 19:42:08 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[exclude]]></category>
		<category><![CDATA[posts]]></category>
		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=592</guid>
		<description><![CDATA[If you use posts within WordPress to generate content, such as Frequently Asked Questions or Help Guides, it&#8217;s quite often the case that you don&#8217;t want these to appear on the posts page of your blog. Instead of having to re-create the whole query, you can append a comma separated list of category ID&#8217;s  that [...]]]></description>
			<content:encoded><![CDATA[<p class="first">If you use posts within <a href="http://wordpress.org/" target="_blank">WordPress</a> to generate content, such as <em>Frequently Asked Questions</em> or <em>Help Guides</em>, it&#8217;s quite often the case that you don&#8217;t want these to appear on the posts page of your blog.</p>
<p>Instead of having to re-create the whole query, you can append a <strong>comma separated list</strong> of category ID&#8217;s  that you want to exclude to the end of the original query and fetch the new data set to be used.<span id="more-592"></span></p>
<p>To achieve this, insert a variation of the following into your index or template file specified as the <strong>posts page</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_string</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;cat=-2,-3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This should be placed <strong>before</strong> the loop, therefore ideally just before:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Adding this line of code will check if the current page is the posts page (<a href="http://codex.wordpress.org/Conditional_Tags#The_Main_Page" target="_blank">is_home</a>) and if so <strong>exclude</strong> the categories with ID&#8217;s 2 and 3. Note here the <strong>negation</strong> used (-2 and -3), without this the query will include rather than exclude the categories.</p>
<p>If you don&#8217;t want to hard code ID values, you could use the <a href="http://codex.wordpress.org/Function_Reference/get_category_by_slug" target="_blank">get_category_by_slug</a> or <a href="http://codex.wordpress.org/Function_Reference/get_category_by_path" target="_blank">get_category_by_path</a> functions to fetch the category ID.</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2010/01/wordpress-exclude-categories-from-homepage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the WordPress mod_rewrite rules</title>
		<link>http://36flavours.com/2009/10/extending-the-wordpress-mod_rewrite-rules/</link>
		<comments>http://36flavours.com/2009/10/extending-the-wordpress-mod_rewrite-rules/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 17:29:23 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[query_vars]]></category>
		<category><![CDATA[rewrite rule]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=423</guid>
		<description><![CDATA[If you have written a WordPress Plug-in, or a highly customised page, and you want to add a custom rewrite rule then this is article is definitely the one for you. We all know that WordPress is a powerful and pretty impressive blogging platform, and contains many useful features. The problem is finding the features [...]]]></description>
			<content:encoded><![CDATA[<p class="first">If you have written a WordPress Plug-in, or a highly customised page, and you want to add a custom rewrite rule then this is article is definitely the one for you.</p>
<p>We all know that <a href="http://wordpress.org/" target="_blank">WordPress</a> is a powerful and pretty impressive blogging platform, and contains many useful features. The problem is finding the features you need / want. Most of the time they are available &#8211; <em>somewhere</em>.<span id="more-423"></span></p>
<p>In this case, after a numbers of hours research, I&#8217;ve done all the hard work for you when it comes to adding custom rewrite rules. We shall assume we have a page called &#8220;<strong>directory</strong>&#8216;&#8221; with the page ID &#8220;<strong>123</strong>&#8221; and the parent page of name &#8220;<strong>business</strong>&#8220;.</p>
<p>This page <em>(ID: 123)</em> looks for the parameter &#8220;business&#8221; and if is defined, displays the details for the corresponding company. We also want to add the location of the business in the url, but for simplicity we will not pass them through in this example.</p>
<p>The end goal is to have a list of businesses displayed on &#8220;<strong>/business/directory/</strong>&#8221; with links to the business details in the format &#8220;<strong>/business/directory/york-yo31/mybusinessltd/</strong>&#8220;.</p>
<p>To achieve this, we will need to make use of three hooks. The first is the &#8220;<a href="http://codex.wordpress.org/Plugin_API/Action_Reference" target="_blank">init</a>&#8221; hook, which we will use to regenerate the rewrite rules and save them to the database using flush_rules().</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> directory_flush_rewrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flush_rules</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'directory_flush_rewrite'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The second hook is &#8220;<a href="http://codex.wordpress.org/Custom_Queries" target="_blank">query_vars</a>&#8220;. This is required to add the string &#8220;business&#8221; to the list of query variables WordPress understands in order for it to be retrieved on our directory page.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> directory_vars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$public_query_vars</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$public_query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'business'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$public_query_vars</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_vars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'directory_vars'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The last hook is called &#8220;<a href="http://codex.wordpress.org/Function_Reference/WP_Rewrite" target="_blank">generate_rewrite_rules</a>&#8221; and allows us to add the custom rewrite rule/s the list of WordPress rewrite rules. Putting the <strong>three code snippets together</strong> will result in the following block of code, which should be added to your &#8220;<strong>functions.php</strong>&#8221; file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> directory_flush_rewrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flush_rules</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'directory_flush_rewrite'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> directory_vars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$public_query_vars</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$public_query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'business'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$public_query_vars</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_vars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'directory_vars'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> directory_rewrite_rules<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_rewrite</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rules</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'business/directory/(?:\w+)-(?:\w+)/(.*)/?'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index.php?page_id=123&amp;business='</span><span style="color: #339933;">.</span><span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">preg_index</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rules</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'generate_rewrite_rules'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'directory_rewrite_rules'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The final piece of information you need is how to access the variable passed through form the rewrite rule (&#8220;<strong>business</strong>=mybusinessltd&#8221;). This can be done using using the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'business'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// returns 'mybusinessltd' in this example.</span></pre></div></div>

<p>The example Reg Exp used could be modified and improved nad the page name could be matched and used instead of using the page id, but should put you on the right track. As mentioned earlier, you could also pass through the the other parameters (town &amp; postcode) and use them alongside business in your lookup query.</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2009/10/extending-the-wordpress-mod_rewrite-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using WP-Syntax and the visual editor</title>
		<link>http://36flavours.com/2009/09/using-wp-syntax-and-the-visual-editor/</link>
		<comments>http://36flavours.com/2009/09/using-wp-syntax-and-the-visual-editor/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 20:09:40 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tinymce]]></category>
		<category><![CDATA[wp-syntax]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=388</guid>
		<description><![CDATA[Many of the blog posts I write tend to be about web development related topics and will often include a number of code snippets. My current choice of syntax highlighter is WP-Syntax, which supports a wide range of popular languages and has the ability to also include line numbers. The problem with using this plug-in [...]]]></description>
			<content:encoded><![CDATA[<p class="first">Many of the blog posts I write tend to be about web development related topics and will often include a number of code snippets. My current choice of syntax highlighter is <a href="http://wordpress.org/extend/plugins/wp-syntax/" target="_blank">WP-Syntax</a>, which supports a wide range of popular languages and has the ability to also include line numbers.</p>
<p>The problem with using this plug-in is that the <a href="http://wordpress.org/" target="_blank">WordPress</a> WYSIWYG Editor (<a href="http://tinymce.moxiecode.com/" target="_blank">TinyMCE</a>), will <strong>remove any tags and attributes</strong> that it believes to be invalid according to it&#8217;s configuration. As two of the attributes used by this plug-in are custom attributes <em>(escaped/line)</em> they are removed, causing some unexpected output.<span id="more-388"></span></p>
<p>One solution to this problem is to add the custom attributes to the list of valid elements by using the &#8216;<strong>tiny_mce_before_init</strong>&#8216; filter and appending them to the &#8216;<strong>extended_valid_elements&#8217;</strong> string.</p>
<p>The function below can be added to the <em>functions.php</em> file within your theme directory:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> tinymce_wp_syntax<span style="color: #009900;">&#40;</span><span style="color: #000088;">$init</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'pre[lang|escaped=true|line]'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$init</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extended_valid_elements'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$init</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extended_valid_elements'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$values</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$init</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extended_valid_elements'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">','</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$init</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tiny_mce_before_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tinymce_wp_syntax'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Adding this to my blog enables me to continue using the visual editor instead of disabling it and at the same time will allow the other HTML filters to continue as normal <img src='http://36flavours.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Note:</strong> You may have to force refresh (ctrl + f5) the post / page editing page for the changes to take effect.</p>
<p><strong>EDIT</strong>: This solution does not fully solve the problem in <a href="http://mu.wordpress.org/">WordPress MU</a> installations, as you need to adjust the allowed post tags used by the content filter.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>CUSTOM_TAGS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$allowedposttags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pre'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'lang'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'escaped'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'true'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'line'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2009/09/using-wp-syntax-and-the-visual-editor/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SMTP server settings for outgoing email using WAMP</title>
		<link>http://36flavours.com/2009/09/smtp-server-settings-for-outgoing-email-using-wamp/</link>
		<comments>http://36flavours.com/2009/09/smtp-server-settings-for-outgoing-email-using-wamp/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 20:03:37 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[wamp]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=345</guid>
		<description><![CDATA[If you&#8217;re running WAMP and need the ability to use the PHP mail function to send outgoing e-mails, then you will need to modify the php.ini settings. As WAMP itself does not have an SMTP server, the easiest option is to replace the SMTP address with the name of the SMTP server or IP Address [...]]]></description>
			<content:encoded><![CDATA[<p class="first">If you&#8217;re running WAMP and need the ability to use the PHP mail function to send outgoing e-mails, then you will need to modify the php.ini settings.</p>
<p>As WAMP itself does not have an SMTP server, the easiest option is to replace the SMTP address with the name of the SMTP server or IP Address with one that you can use.<span id="more-345"></span></p>
<p>This can be achieved by either editing the php.ini directly, replacing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">;SMTP = localhost
;smtp_port = <span style="color: #000000;">25</span>
;sendmail_from =</pre></div></div>

<p>with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP = smtp.yourisp.com
smtp_port = <span style="color: #000000;">25</span>
sendmail_from = me<span style="color: #000000; font-weight: bold;">@</span>example.com</pre></div></div>

<p>Or by setting the values in PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SMTP&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;smtp.yourisp.com&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp_port'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sendmail_from'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'me@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Replace <strong>smtp.yourisp.com</strong> with that of your ISP&#8217;s SMTP server, for example <strong>smtp.ntlworld.com</strong>.</p>
<p>Depending on your current settings, it&#8217;s likely that you may only need to modify the SMTP value as the others &#8211; <em>smtp_port and sendmail_from</em> &#8211; may already be defined.</p>
<p>Now restart the <span id="SPELLING_ERROR_16">Apache</span> server in order for your changes take effect, then test the changes by calling the <a href="http://uk3.php.net/manual/en/function.mail.php" target="_blank">PHP mail</a> function.</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2009/09/smtp-server-settings-for-outgoing-email-using-wamp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WP &#8211; Enable read more links for pages</title>
		<link>http://36flavours.com/2009/08/wp-enable-read-more-links-for-pages/</link>
		<comments>http://36flavours.com/2009/08/wp-enable-read-more-links-for-pages/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 13:11:21 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[2.8.4]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[the_loop]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=287</guid>
		<description><![CDATA[When listing pages using the_loop(), the latest version of WordPress (2.8.4) does not allow for a &#8220;Read more&#8230;&#8221; link to be appended to a list of pages using the_content() along with the &#60;!&#8211;more&#8211;&#62; quicktag. Although it wasn&#8217;t immediately obvious to me, read more links can be enabled by over-riding the global $more variable and setting [...]]]></description>
			<content:encoded><![CDATA[<p class="first">When listing pages using <em>the_loop()</em>, the latest version of WordPress (<em>2.8.4</em>) does not allow for a &#8220;Read more&#8230;&#8221; link to be appended to a list of pages using <em>the_content()</em> along with the &lt;!&#8211;more&#8211;&gt; quicktag.</p>
<p>Although it wasn&#8217;t immediately obvious to me, read more links can be enabled by over-riding the global <em><strong>$more</strong></em> variable and setting it to <em>false</em>, <strong>before looping</strong> through the result set, for example:<span id="more-287"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$more</span><span style="color: #339933;">;</span> <span style="color: #000088;">$more</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_type=page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Read More...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span></pre></div></div>

<p>I couldn&#8217;t actually discover why this is not the default behaviour when querying pages. There may be a good reason behind it, but in my experience I found it mildly irritating.</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2009/08/wp-enable-read-more-links-for-pages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP &#8211; Add class name to first paragraph in blog post</title>
		<link>http://36flavours.com/2009/08/wp-add-class-name-to-first-paragraph-in-blog-post/</link>
		<comments>http://36flavours.com/2009/08/wp-add-class-name-to-first-paragraph-in-blog-post/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 15:04:27 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=273</guid>
		<description><![CDATA[When re-designing my blog I wanted to display the first paragraph of each blog post in bold text. A CSS3 selector could have been used, but wouldn&#8217;t work in older browsers such as IE6. Instead I decided to write a very simple function to add a class name to the first paragraph by filtering the [...]]]></description>
			<content:encoded><![CDATA[<p class="first">When re-designing my blog I wanted to display the <strong>first paragraph</strong> of each blog post in <strong>bold text</strong>. A CSS3 selector could have been used, but wouldn&#8217;t work in older browsers such as <strong>IE6</strong>.</p>
<p>Instead I decided to write a very simple function to add a class name to the first paragraph by filtering the content, then setting the styles accordingly in my theme CSS file.<span id="more-273"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> first_paragraph<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;p([^&gt;]+)?&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;p$1 class=&quot;first&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'first_paragraph'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By default this will append <em>class=&#8221;first&#8221;</em> to the first p tag in your post.</p>
<p>If you want to use this function on your own blog, just add it to your (or create a) <strong> functions.php</strong> file within your themes folder.</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2009/08/wp-add-class-name-to-first-paragraph-in-blog-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple PHP Sparklines</title>
		<link>http://36flavours.com/2008/04/simple-php-sparklines/</link>
		<comments>http://36flavours.com/2008/04/simple-php-sparklines/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 22:16:24 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[gdlib]]></category>
		<category><![CDATA[sparkline]]></category>

		<guid isPermaLink="false">http://sha.re.it/?p=15</guid>
		<description><![CDATA[Whilst designing a new layout for one of my current projects, I wanted to be able to provide the end user with the ability to quickly scan over a series of statistics. The main page should act as overview of everything that is going on, therefore I wanted to avoid overcrowding it with lots of [...]]]></description>
			<content:encoded><![CDATA[<p class="first">Whilst designing a new layout for one of my current projects, I wanted to be able to provide the end user with the ability to quickly scan over a series of statistics.</p>
<p>The main page should act as overview of everything that is going on, therefore I wanted to avoid overcrowding it with lots of large graphs and instead simply show the basic trends.</p>
<p>A few months back I came across an implementation of <a title="Sparkline From Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Sparkline" target="_blank">Sparklines</a> &#8211; data-intense, design-simple, word-sized graphics &#8211; which are often used to demonstrate stock market activity in a simple visual graphic.</p>
<p>I was just going to use a pre-made script from the many already available, but instead decided to knock one up myself and created a small <a title="PHP Class Source Code" href="http://sha.re.it/wp-content/examples/sparkline/sparkline.class.phps" target="_blank">PHP Class</a> to generate and output a sparkline image using the GD Library.</p>
<p>To create a sparkline I can now simply include the class and then initiate it in a variation of the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sparkline</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Sparkline<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">38</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #339933;">...</span> <span style="color: #339933;">,</span><span style="color: #cc66cc;">38</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">13</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>output<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Display image</span></pre></div></div>

<p>This PNG image is generated and output to the browser:</p>
<p style="text-align: center;"><img src="http://sha.re.it/wp-content/examples/sparkline/example1.php" alt="Example Sparkline" width="120" height="40" /></p>
<p style="text-align: left;">A number of other setup options are available to customise the output further:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>bg <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#000000'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Background colour</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>width <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>height <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>line <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#336699'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Line colour</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>points <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#333333'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Start &amp;amp; end points</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>thickness <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Line thickness</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>scale <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Anti-aliasing scale size</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>output<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'saved/test.png'</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> <span style="color: #666666; font-style: italic;">// Save to location and display</span></pre></div></div>

<p style="text-align: center;"><img src="http://sha.re.it/wp-content/examples/sparkline/example2.php" alt="Customised Sparkline" width="180" height="60" /></p>
<p style="text-align: left;">All colours must be provided in hexadecimal format and if you are attempting to save the image the destination location must be writeable by Apache.</p>
<p style="text-align: left;">The <a title="PHP Class Source Code" href="http://sha.re.it/wp-content/examples/sparkline/sparkline.class.phps" target="_blank">Sparkline PHP Class source code</a> is available for anyone to use as they may like, although I must confess it hasn&#8217;t been fully tested as yet!</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2008/04/simple-php-sparklines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
