<?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>Inspect Element &#187; php</title>
	<atom:link href="http://inspectelement.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://inspectelement.com</link>
	<description>Web Design &#38; Development Blog</description>
	<lastBuildDate>Wed, 25 Jan 2012 09:55:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to Create a Theme Development Environment for a Live WordPress Site</title>
		<link>http://inspectelement.com/tutorials/create-a-wordpress-theme-development-environment/</link>
		<comments>http://inspectelement.com/tutorials/create-a-wordpress-theme-development-environment/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 09:44:31 +0000</pubDate>
		<dc:creator>Tom Kenny</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://inspectelement.com/?p=5872</guid>
		<description><![CDATA[Any good website owner knows that they need to be constantly looking at ways to improve their site even through small little tweaks. If you're using <strong>Wordpress</strong> you'll notice that it isn't easy to create a development version without creating a separate installation. Of course, you can make changes directly on a live WordPress site but that isn't recommended for anything other than minor tweaks.]]></description>
			<content:encoded><![CDATA[<p>Any good website owner knows that they need to be constantly looking at ways to improve their site even through small little tweaks. If you&#8217;re using <strong>WordPress</strong> you&#8217;ll notice that it isn&#8217;t easy to create a development version without creating a separate installation. Of course, you can make changes directly on a live WordPress site but that isn&#8217;t recommended for anything other than minor tweaks.</p>
<p><img class="alignnone size-full wp-image-6027" title="themeDevEnvironment" src="http://inspectelement.com/wp-content/uploads/2010/01/themeDevEnvironment3.jpg" alt="" width="555" height="216" /></p>
<p>With the help of an excellent plugin for WordPress called <a href="http://www.nkuttler.de/wordpress/theme-switch-and-preview-plugin/">Theme switch and preview</a>, this tutorial will allow you to easily switch between the live site and development versions using two different themes on the same installation of WordPress. We&#8217;ll do this by creating a bar at the top of the page which will clearly show you if you&#8217;re viewing the live theme (what everyone else sees) or the development theme with a link to switch between the two.</p>
<p>While there may well be a Worpdress plugin that does everything below, it&#8217;s much more rewarding and satisfying to create your own solution.</p>
<p><span id="more-5872"></span><strong> </strong></p>
<h3><strong>Step 1: Install Theme Switcher WordPress Plugin</strong></h3>
<p>First step is to install the aforementioned plugin, <a href="http://wordpress.org/extend/plugins/theme-switcher/">Theme switch and preview</a>. You can access the configuration for Theme Switcher in the settings section of the WordPress admin sidebar on the left where you can also find a list of all the available themes.</p>
<div id="attachment_5887" class="wp-caption alignnone" style="width: 557px"><img class="size-full wp-image-5887" title="themes" src="http://inspectelement.com/wp-content/uploads/2010/01/themes.gif" alt="" width="547" height="58" /><p class="wp-caption-text">Screenshot of the themes installed on Inspect Element as seen in Theme Switcher&#39;s settings.</p></div>
<p>By clicking any of the links above, you can switch between themes without activation allowing you to see what a different theme looks like without affecting what your visitors sees. They will still see the activated theme.</p>
<h3><strong>Step 2: Create a Copy of the Current Theme</strong></h3>
<p>This is as easy as just duplicating the theme folder in you WordPress theme directory. Make sure to change the name of the theme as it is what Theme Switcher relies on to distinguish between installed themes.</p>
<p><img class="alignnone size-full wp-image-5890" title="themeName" src="http://inspectelement.com/wp-content/uploads/2010/01/themeName.gif" alt="" width="337" height="130" /></p>
<p>You can see from the screenshots above that Theme Switcher uses the &#8216;Theme Name&#8217; but WordPress also picks up on this in the Themes section of the admin area so it&#8217;s a good practice to stick to with for any theme. Here I&#8217;ve added dev in brackets to use for my development theme.</p>
<h3>Step 3: Add the Dev Bar to the Live Theme</h3>
<p>One of the best ways to indicate what theme you&#8217;re viewing is to add a colour coded bar at the top of the page when logged in. We need to use a bit of PHP to determine if you&#8217;re logged in. Open up the <strong>header.php</strong> file in your live theme and paste in the following code directly below the <em>&lt;body&gt;</em> tag.</p>
<pre><code>&lt;?php if ( is_user_logged_in() ) : ?&gt;

 	// Insert dev bar code here

&lt;?php else : ?&gt;

	// Nothing here

&lt;?php endif; ?&gt;</code></pre>
<p>So that&#8217;s a simple bit of WordPress PHP to see if you&#8217;re logged in or not expressed as an if else statement. Of course you&#8217;ll want to include some HTML for the bar itself. We&#8217;re going to insert a div and a link to the dev version as well as a title.</p>
<pre><code class="php">&lt;?php if ( is_user_logged_in() ) : ?&gt;

	&lt;div id="devbar" class="live"&gt;

		&lt;p&gt;Live Site&lt;/p&gt;

		&lt;a href="&lt;?php pageURL(); ?&gt;?theme=Inspect+Element+v3+%28dev%29"&gt;Switch to Dev&lt;/a&gt;

	&lt;/div&gt;

&lt;?php else : ?&gt;

	// Nothing here

&lt;?php endif; ?&gt;</code></pre>
<p>For the link to the dev theme, you need to go back to the settings page for the Theme Switcher plugin and copy the link your development theme. This is the link you&#8217;ll use in your live dev bar. There&#8217;s one small amendment to make here. Replace everything before the <em>?theme=</em> with a function that gets the current url so that you&#8217;ll remain on the same page when switching between themes.</p>
<p>For this to work, you need to open up the <strong>functions.php</strong> file in your live theme and paste in the following code:</p>
<pre><code>function pageURL() {
    $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {
        $pageURL .= "s";
    }
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     }
    else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }</code></pre>
<p>Source: <a href="http://www.kisaso.com/how-to-get-the-current-url-of-web-page-in-php/">How to get the current URL of web page in PHP</a> (Note: I&#8217;ve changed the name of the function from <em>kish_trans_curPageUR</em>L to <em>pageURL </em>to keep things simple.)</p>
<h3>Step 4: Add the Dev Bar to the Development Theme</h3>
<p>Follow the same as above but this time insert the code into the development theme files. Also you&#8217;ll need to modify the code in the link on the <strong>header.php</strong> to go back to the live version.</p>
<pre><code class="php">&lt;?php if ( is_user_logged_in() ) : ?&gt;

	&lt;div id="devbar" class="dev"&gt;

		&lt;p&gt;Development Site&lt;/p&gt;

		&lt;a href="&lt;?php pageURL(); ?&gt;?theme=Inspect+Element+v3"&gt;Switch to Live&lt;/a&gt;

	&lt;/div&gt;

&lt;?php else : ?&gt;

	// Nothing here

&lt;?php endif; ?&gt;</code></pre>
<h3>Step 5: Style the Dev Bar</h3>
<p>Obviously you have free reign to do what you want here with any CSS you want with any code you&#8217;ve chosen to use for the dev bar. We&#8217;re going to give the dev bar a red background and make it span the width of the browser.</p>
<pre><code class="css">#devbar.live { background-color: red; width: 100%; height 50px; }</code></pre>
<p>Now you&#8217;ll want to make the bar on the live site look different to the development site so that you know which one you&#8217;re on at a quick glance.</p>
<pre><code class="css">#devbar.dev { background-color: green; width: 100%; height 50px; }</code></pre>
<p>Place these in the respective CSS files for the live theme and the development theme.</p>
<h4>Additional Styling</h4>
<p>Something that I like to do is to use the &#8216;logged-in&#8217; class that WordPress appends to the body tag when you&#8217;re logged in to add an extra visual guide for each theme.</p>
<p>In the live theme&#8217;s CSS, I&#8217;ve I like to add the following:</p>
<pre><code class="css">body.logged-in { border-left: 30px solid green; }</code></pre>
<p>And in the development theme&#8217;s CSS:</p>
<pre><code class="css">body.logged-in { border-left: 30px solid red; }</code></pre>
<p>This gives a big visual indicator of what theme you are currently viewing. If there is a big green bar on the left, you&#8217;re seeing what your visitors see and if the bar is red, you&#8217;re viewing the development version. This comes in very handy when you scroll down the page and can no longer see the dev bar.</p>
<p><a href="http://inspectelement.com/wp-content/uploads/2010/01/inspectElementLive.jpg"><img class="alignnone size-full wp-image-5987" title="inspectElementLiveSm" src="http://inspectelement.com/wp-content/uploads/2010/01/inspectElementLiveSm.jpg" alt="" width="555" height="132" /></a></p>
<p><a href="http://inspectelement.com/wp-content/uploads/2010/01/inspectElementDev.jpg"><img class="alignnone size-full wp-image-5986" title="inspectElementDevSm" src="http://inspectelement.com/wp-content/uploads/2010/01/inspectElementDevSm.jpg" alt="" width="555" height="132" /></a></p>
<p>The screenshots above (click for larger versions) show how I&#8217;ve implemented this into Inspect Element with the use of some extra CSS styling and a couple of icons.</p>
<h3>Step 6: Temporarily Hide the Dev Bar with jQuery</h3>
<p>There will be times where you want to see your site without the dev bar and border on the left just as people on the outside see it. The simplest way of achieving this is to use some basic jQuery. The following is code I&#8217;ve implemented to hide the dev bar and the border on the left when the paragraph (&#8216;Live Site&#8217; and &#8216;Development Site&#8217; text) of the dev bar is clicked.</p>
<pre><code>&lt;script type="text/javascript"&gt;

$(document).ready(function(){
	$("#devbar p").css('cursor','pointer').click(function () {
		$("#devbar").hide();
		$("body.logged-in").css('border','none');
	});
});

&lt;/script&gt;</code></pre>
<p>Simply put, this code hides the dev bar <em>and</em> removes the left border on the body when you click on the #devbar p element in the dev bar. You may consider adding a button dedicated to this function instead.</p>
<p>It&#8217;s best to place this within the code that determines if the dev bar should be shown as in step 3. That way it will only load when the dev bar code is available and not when it isn&#8217;t needed. Also, don&#8217;t forget you need to include the jQuery library if your site doesn&#8217;t already, or this part won&#8217;t work.</p>
<h4>Bring the Dev Bar back with Keyboard Shortcuts</h4>
<p>What if you want to bring the dev bar and left border back? It will return either when you refresh the page or navigate to another part of the site but we&#8217;ve hidden it with jQuery, so why not bring it back with some additional jQuery in the form of a keyboard shortcut.</p>
<p>The following code will hide the dev bar and remove the left border when the letter &#8216;N&#8217; is pressed and bring it back when pressing &#8216;Y&#8217;.</p>
<pre><code>&lt;script type="text/javascript"&gt;

	$(document).bind('keydown', function(evt) {
		switch(evt.which) {
			case 78:	// letter 'n'
				$("#devbar").hide();
				$("body.logged-in").css('border','none');
				break;
			case 89:	// letter 'y'
				$("#devbar").show();
				$("body.logged-in").css('border-left','30px solid #972324');
				break;
		}
	});

&lt;/script&gt;</code></pre>
<h3>Create Your Own</h3>
<p>Ideally this is meant for designers who run their own site or manage an existing client&#8217;s site through WordPress. I&#8217;ve only been using this for couple of days now and already it&#8217;s made a world of difference whenever I want to make any changes but need to test before making them live.</p>
]]></content:encoded>
			<wfw:commentRss>http://inspectelement.com/tutorials/create-a-wordpress-theme-development-environment/feed/</wfw:commentRss>
		<slash:comments>72</slash:comments>
		</item>
		<item>
		<title>Add a Category and Page Specific Class to the Body Tag in WordPress</title>
		<link>http://inspectelement.com/didyouknow/add-a-class-to-the-body-tag-in-wordpress/</link>
		<comments>http://inspectelement.com/didyouknow/add-a-class-to-the-body-tag-in-wordpress/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 08:00:05 +0000</pubDate>
		<dc:creator>Tom Kenny</dc:creator>
				<category><![CDATA[did you know...?]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://tkenny.co.uk/inspectelement/?p=231</guid>
		<description><![CDATA[WordPress is a powerful CMS, especially for blogging but what if you want to style something on a single page and not affect anything on other pages? There isn&#8217;t built-in way to do this so we need to use the platform that WordPress runs on by writing some custom PHP. &#60;?php if (is_home()) { ?&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1549" title="wordpress" src="http://inspectelement.com/wp-content/uploads/2009/05/wordpress1.jpg" alt="wordpress" width="560" height="218" /></p>
<p>WordPress is a powerful CMS, especially for blogging but what if you want to style something on a single page and not affect anything on other pages? There isn&#8217;t built-in way to do this so we need to use the platform that WordPress runs on by writing some custom PHP.</p>
<p><span id="more-231"></span></p>
<pre lang="PHP">&lt;?php if (is_home()) { ?&gt;
&lt;body id="home"&gt;
&lt;?php } else if (is_category('articles')) { ?&gt;
&lt;body id="articles"&gt;
&lt;?php } else if (is_category('offers')) { ?&gt;
&lt;body id="offers"&gt;
&lt;?php } else if (is_category('general')) { ?&gt;
&lt;body id="general"&gt;
&lt;?php } else if (is_page('about us')) { ?&gt;
&lt;body id="about"&gt;
&lt;?php } else if (is_page('contact us')) { ?&gt;
&lt;body id="contact"&gt;
&lt;?php } ?&gt;</pre>
<p>Above you can see a big if else statementÂ that will assign and id to the &lt;body&gt; tag depending on what page or category the user is viewing. Now we can target specific pages for styling in the CSS.</p>
<pre>body#offers p { color: red; }
body#about p { color: green; }
body#contact p { color: black; }</pre>
<p>This is a very simple example but you can go more complex such as having different colours for a navigation bar within different sections or change layout on one page without affecting any other pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://inspectelement.com/didyouknow/add-a-class-to-the-body-tag-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

