<?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>Maddison Designs &#187; PHP</title>
	<atom:link href="http://maddisondesigns.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://maddisondesigns.com</link>
	<description>Professional Web Design &#38; Development</description>
	<lastBuildDate>Wed, 25 Jan 2012 07:33:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Never Ever Have Blank Lines Outside Your WordPress PHP Tags</title>
		<link>http://maddisondesigns.com/2010/03/never-ever-have-blank-lines-outside-your-wordpress-php-tags/</link>
		<comments>http://maddisondesigns.com/2010/03/never-ever-have-blank-lines-outside-your-wordpress-php-tags/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 23:13:45 +0000</pubDate>
		<dc:creator>Anthony Hortin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://maddisondesigns.info/?p=897</guid>
		<description><![CDATA[I had my day planned out nicely. Only a few minor updates to make on my WordPress theme for my new site and I would&#8217;ve been done (coding wise). Then it happened! I logged into the admin Dashboard to make a few content tweaks and things seemed a bit strange. When I tried to save some content updates, the page<p><a class="more-link" href="http://maddisondesigns.com/2010/03/never-ever-have-blank-lines-outside-your-wordpress-php-tags/" title="Continue reading &#8216;Never Ever Have Blank Lines Outside Your WordPress PHP Tags&#8217;">Continue Reading &#8594;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I had my day planned out nicely. Only a few minor updates to make on my <a title="Wordpress website" href="http://wordpress.org">WordPress</a> theme for my new site and I would&#8217;ve been done (coding wise). Then it happened! I logged into the admin Dashboard to make a few content tweaks and things seemed a bit strange. When I tried to save some content updates, the page just wouldn&#8217;t refresh properly. I even tried logging out of the dashboard&#8230; But still no luck <img src='http://maddisondesigns.com/wp-includes/images/smilies/icon_cry.gif' alt=':cry:' class='wp-smiley' /> </p>
<p><span id="more-897"></span></p>
<p>Next up, I tested the site to see if it was up and running ok. On the surface things looked fine but then I noticed that when I tried to type in a URL without the trailing forward-slash (&#8216;/&#8217;), the page wouldn&#8217;t appear. Normally, depending on how you&#8217;ve configured your <a title="Permalinks on the WordPress Codex" href="http://codex.wordpress.org/Using_Permalinks">Permalinks</a>, it will simply add the trailing slash automatically. Instead, all I got was a blank white screen starring back at me. Needless to say, a few expletives were uttered!</p>
<p>I tried thinking back to when everything seemed to be working fine. I also tried to remember what changes I&#8217;d made the day before. From memory, it was mainly some CSS updates to change links colours. There were no major code updates from what I could remember. I also couldn&#8217;t work out why the URL&#8217;s weren&#8217;t being processed correctly. After doing some Googling, I decided to raise a (low priority) support ticket with my hosting provider to see if any server changes had been made within the last few days. It was as if the .htaccess rules weren&#8217;t being obeyed. Good and bad news. The good news&#8230; no changes had been made to the server. The bad news&#8230; this didn&#8217;t get me any closer to resolving my issue.</p>
<p>The next step was to try changing to the default WordPress theme and do some testing. Things seemed to improved after changing themes. I could save my pages consistently. I could log in and out of the Dashboard without a problem. Even the URL&#8217;s worked fine, with or without the trailing slashes. Hmmm It would appear that the culprit was my own theme, which I&#8217;d been lovingly hand crafting. Next test was a restore from a backup of my theme. Luckily I&#8217;m quite strict at performing backups. I perform a backup of my workstation and my development server every couple of days, with the files kept on a separate hard drive. I rotate between 4 different sets for each machine. I restored the oldest backup which was just over a week old. Sure enough, everything worked fine. The next backup I tried was one from only two days prior. This also worked fine. Things were starting to look up! What this meant was that I&#8217;d narrowed it down to being caused by the changes that I&#8217;d made the previous day.</p>
<p>I now needed to compare the latest version of my code (the one with the problems) to the version from two days prior. I downloaded and installed <a title="WinMerge website" href="http://winmerge.org">WinMerge</a>, which is an extremely handy Open Source differencing and merging tool (for Windows). Luckily there weren&#8217;t too many files changed. As mentioned earlier, most of the changes were in my main stylesheet. Starting from a copy of my restored (working) theme, I slowly started to integrate the changes that I&#8217;d made the previous day. Most seemed fairly mundane. A few CSS changes and some very minor code updates. I then got to my <em>functions.php</em> file. I incorporated the changes and lo and behold, things broke immediately. Yay!! I&#8217;d found the damn file that was causing all my problems! Now it was simply a matter of narrowing down the exact cause.</p>
<p>Looking through the code reminded me of the changes that I&#8217;d made. I&#8217;d added a few comments to the code to document a couple of the functions (Silly me, I know! Real developers don&#8217;t document code!!). The other thing I&#8217;d done was to add a blank line in between where I&#8217;d closed a PHP tag and opened up the next one. The code snippet is question looked like this&#8230;</p>
<p style="text-align: center;"><img class="size-full wp-image-899 aligncenter" title="functions-php-code-fragment-before" src="http://maddisondesigns.com/wp-content/uploads/2010/03/functions-php-code-fragment-before.jpg" alt="" width="600" height="150" /></p>
<p>You&#8217;ll notice that between the closing PHP tag and the following opening tag, there&#8217;s a blank line. Gasp!! This is what was causing all the drama! The solution was to simply remove the offending blank line. In fact, since I was simply closing the PHP tag and immediately reopening it, I could easily omit both of them. The resulting code looked like&#8230;</p>
<p style="text-align: center;"><img class="size-full wp-image-898 aligncenter" title="functions-php-code-fragment-after" src="http://maddisondesigns.com/wp-content/uploads/2010/03/functions-php-code-fragment-after.jpg" alt="" width="600" height="150" /></p>
<p>As for the problems that it caused, well there were quite are few.</p>
<h3>URL&#8217;s weren&#8217;t processed properly</h3>
<p>Since my Permalinks were setup using the format &#8220;<em><strong>/%year%/%monthnum%/%postname%/</strong></em>&#8220;, the posts wouldn&#8217;t display properly if they didn&#8217;t have the trailing slash. Normally, this is something that is handled by your <em>.htaccess</em> file. Instead, I was simply receiving a blank page unless I specifically had the slash on the end of the URL.</p>
<h3>Strange content appearing</h3>
<p>This was a strange one. As you can see in the image below, characters such as quotes and apostrophes were being rendered incorrectly. You&#8217;d think this was because their was some &#8216;strange&#8217; characters stored in the database, but nope, it displayed perfectly fine once <em>functions.php</em> was fixed.</p>
<p style="text-align: center;"><img class="size-full wp-image-901 aligncenter" title="invalid-characters-being-rendered" src="http://maddisondesigns.com/wp-content/uploads/2010/03/invalid-characters-being-rendered.jpg" alt="" width="600" height="150" /></p>
<h3>Blank lines appearing at top of document source, before the DOCTYPE</h3>
<p>One of the repercussions of the blank line &#8220;incident&#8221; was that it caused blank lines to appear before the DOCTYPE within the html. This can cause problems with your RSS feed, in particular with Feedburner. Blank lines (outside of PHP tags) in any of your page templates can also cause the same problem, so I made sure I thoroughly checked those as well.</p>
<h3>Problems in the WP Dashboard</h3>
<p>As mentioned above, one of the first things that alerted me to the problem was my administration dashboard becoming unstable. I found that whenever I tried to save some content changes, the page wouldn&#8217;t refresh. Also, I couldn&#8217;t even log out of the WordPress Dashboard. I was able to browse through the various menu options within the Dashboard, but when it came to performing an action such as saving a page, that&#8217;s when the problems surfaced.</p>
<p>Due the the &#8216;strangeness&#8217; of some of the problems, this was one bug that took a while to track down. Thankfully though, it&#8217;s all fixed now. It&#8217;s certainly something that I&#8217;ll be more mindful of in the future when I create themes.</p>
<p>Have you come across this problem or any other strange issues? I&#8217;d love to hear, so feel free to leave a comment <img src='http://maddisondesigns.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://maddisondesigns.com/2010/03/never-ever-have-blank-lines-outside-your-wordpress-php-tags/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>How To Add Multiple Widget Sidebars To Your WordPress Blog</title>
		<link>http://maddisondesigns.com/2010/03/how-to-add-multiple-widget-sidebars-to-your-wordpress-blog/</link>
		<comments>http://maddisondesigns.com/2010/03/how-to-add-multiple-widget-sidebars-to-your-wordpress-blog/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 07:23:32 +0000</pubDate>
		<dc:creator>Anthony Hortin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Widgets]]></category>

		<guid isPermaLink="false">http://maddisondesigns.info/?p=810</guid>
		<description><![CDATA[I’ve found that the term “sidebar” within WordPress can have multiple meanings. Within your index.php file you will most likely find a call to the php function get_sidebar(). This is referring to the sidebar column, sometimes called the right-hand (or left-hand) navigation column. A sidebar also refers to the location where you add all your Widgets. The Widgets control the<p><a class="more-link" href="http://maddisondesigns.com/2010/03/how-to-add-multiple-widget-sidebars-to-your-wordpress-blog/" title="Continue reading &#8216;How To Add Multiple Widget Sidebars To Your WordPress Blog&#8217;">Continue Reading &#8594;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I’ve found that the term “sidebar” within WordPress can have multiple meanings. Within your <em>index.php</em> file you will most likely find a call to the php function <em>get_sidebar()</em>. This is referring to the sidebar column, sometimes called the right-hand (or left-hand) navigation column. A sidebar also refers to the location where you add all your Widgets. The Widgets control the content that appears within the sidebar (column) and will usually display lists such as your Recent Posts, Categories, Links or dozens of other items.</p>
<p><span id="more-810"></span></p>
<p>Since WordPress is so configurable, it’s possible to have multiple sidebar columns defined such as when you have multiple page templates set up. For example, you may have a specific page template defined for your sites static homepage. As well as defining the body content for that page, you can also define a separate sidebar in case you would like it to appear differently from the rest of the site.</p>
<p>It’s also possible to register multiple sidebars that contain all the widgets. This latter sidebar is what we’ll be discussing here. A typical WordPress theme may only have one sidebar configured although it’s not uncommon to have 2 or 3 or even more. Even though it’s called a “sidebar” it doesn’t need to specifically reside in the sidebar of your website. You can add a “sidebar” to anywhere in your site you want to display your widgets. A common place to include them is the site footer.</p>
<h2>Defining your new sidebar</h2>
<p>Adding additional sidebars to your site is relatively easy. Within your <em>functions.php</em> file you will most likely have something similar to the code below, for your existing sidebar.</p>
<pre>&lt;?php

if ( function_exists('register_sidebar') ) {

   register_sidebar(array(
   'before_widget' =&gt; '&lt;li id="%1$s" class="widget %2$s"&gt;',
   'after_widget' =&gt; '&lt;/li&gt;',
   'before_title' =&gt; '&lt;h2 class="widgettitle"&gt;',
   'after_title' =&gt; '&lt;/h2&gt;'
   ));

}?&gt;</pre>
<p>To add another sidebar you simply need to register another instance. If you are registering more than one, then you will also need to name them. Change your <em>functions.php</em> file to look like the following. Take care to add in the extra line that specifies the name of your sidebar. Once these are functions are defined, you will notice the extra sidebar appear in the WordPress Dashboard under the <em>Appearance &gt; Widgets</em> option. It’s here that you can drag and drop all your widgets into your various sidebars.</p>
<pre>&lt;?php

if ( function_exists('register_sidebar') ) {

   register_sidebar(array(
   'name' =&gt; 'sidebar 1',
   'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
   'after_widget' =&gt; '&lt;/div&gt;',
   'before_title' =&gt; '&lt;h2&gt;',
   'after_title' =&gt; '&lt;/h2&gt;'
    ));

   register_sidebar(array(
   'name' =&gt; 'footer sidebar 1',
   'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
   'after_widget' =&gt; '&lt;/div&gt;',
   'before_title' =&gt; '&lt;h2&gt;',
   'after_title' =&gt; '&lt;/h2&gt;'
   ));

}?&gt;</pre>
<p>You can find more details on the various parameters of the above call on the <a title="register_sidebar function on the WordPress Codex" href="http://codex.wordpress.org/Function_Reference/register_sidebar">WordPress Codex</a>.</p>
<h2>Adding your new sidebar to your template</h2>
<p>Within your <em>sidebar.php</em> file, change the call to your existing sidebar to include its name that you defined within the <em>functions.php</em> file earlier.</p>
<pre>&lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar 1') ) : ?&gt;

   &lt;h2&gt;Articles by month&lt;/h2&gt;
   &lt;ul&gt;
      &lt;?php wp_get_archives('title_li=&amp;type=monthly'); ?&gt;
   &lt;/ul&gt;
   &lt;h2&gt;Categories&lt;/h2&gt;
   &lt;ul&gt;
      &lt;?php wp_list_categories('show_count=0&amp;title_li='); ?&gt;
   &lt;/ul&gt;

&lt;?php endif; ?&gt;</pre>
<p>To add your new sidebar, you can either copy the above code or you can simply copy the following lines. Add these lines to wherever you’d like your new widgets to appear. In this example you can see from the name that I’m placing mine in the footer of my website. As before, don’t forget to specify the correct sidebar name. In the above code, the html that appears between the php statements is what will appear when there are no widgets added to your sidebar. This ‘default’ code can obviously be modified to suit your theme. In the following code, since there is no extra html, nothing will be displayed unless a widget has been added into the sidebar within your WordPress dashboard.</p>
<pre>&lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('footer sidebar 1') ) : ?&gt;
&lt;?php endif; ?&gt;</pre>
<p>You will now find that your site has two widgetized sidebars. As mentioned earlier, there’s no reason why you couldn’t include further ones. It’s simply a matter of registering the new sidebar and then including the php to display it, in the relevant part of your site template.</p>
<p>I’ve also published this tutorial on <a title="Twitter Study Group website" href="http://www.twitterstudygroup.com/wordpress/?p=92">Twitter Study Group</a>. It&#8217;s a great place to learn, so check it out.</p>
<p><a class="noborder" href="http://www.twitterstudygroup.com/wordpress/?p=92"><img class="size-full wp-image-813" title="twitter-study-group-logo" src="http://maddisondesigns.com/wp-content/uploads/2010/03/twitter-study-group-logo.jpg" alt="" width="385" height="77" /></a></p>
<p>Thinking of adding more widgets to your WordPress site? Leave a comment and let me know if you found this useful. Thanks <img src='http://maddisondesigns.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://maddisondesigns.com/2010/03/how-to-add-multiple-widget-sidebars-to-your-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

