<?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>NeonBlue Dreams &#187; code</title>
	<atom:link href="http://neonblueweb.co.uk/dreams/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://neonblueweb.co.uk/dreams</link>
	<description>Living on the edge looking in - the random ramblings of a geek girl</description>
	<lastBuildDate>Tue, 19 Jan 2010 21:45:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Woo hoo! I didded it! (and a rather nifty PHP include menu)</title>
		<link>http://neonblueweb.co.uk/dreams/2008/02/12/woo-hoo-i-didded-it-and-a-rather-nifty-php-include-menu/</link>
		<comments>http://neonblueweb.co.uk/dreams/2008/02/12/woo-hoo-i-didded-it-and-a-rather-nifty-php-include-menu/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 00:10:09 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
				<category><![CDATA[Geeky stuff]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://neonblueweb.co.uk/dreams/2008/02/12/woo-hoo-i-didded-it-and-a-rather-nifty-php-include-menu/</guid>
		<description><![CDATA[It feels like ages since I&#8217;ve done a site from scratch &#8211; just lately all I seem to have been working on is re-designs and re-brandings, so it&#8217;s made a nice change to get back to doing some original design work, and this weekend I finished off a one-page sample for a client. The basic [...]]]></description>
			<content:encoded><![CDATA[<p>It feels like ages since I&#8217;ve done a site from scratch &#8211; just lately all I seem to have been working on is re-designs and re-brandings, so it&#8217;s made a nice change to get back to doing some original design work, and this weekend I finished off a one-page sample for a client. The basic design&#8217;s there, and I have to say I&#8217;m pretty pleased with it, though I&#8217;ve not finished putting in all the various  PHP includes that make life so much easier further down the line if you have to add in pages etc. to the navigation that you hadn&#8217;t accounted for.</p>
<p>One of my favourites of these is a rather nifty PHP include menu which means you can use an include for your navigation list, but still have the current page highlighted in the site&#8217;s navigation, without needing extra markup like adding an ID to the &#8216;body&#8217; element. I can&#8217;t accept the credit for this one because it&#8217;s not something I coded, but I&#8217;ve been using it for so long now that I can&#8217;t remember where I first found it.</p>
<p>All you need is two bits for the navigation; your unordered list for your navigation, which of course you can style in any way you so desire using  CSS, and a tiny little PHP snippet. First you&#8217;ve got your unordered list (I save mine as &#8216;menu.html&#8217;):</p>
<p><pre class="brush: html">&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;mylink1.php&quot;&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;mylink2.php&quot;&gt;Link 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;mylink3.php&quot;&gt;Link 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;mylink4.php&quot;&gt;Link 4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;mylink5.php&quot;&gt;Link 5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; </pre><br />
 Then all you need&#8217;s your PHP snippet:</p>
<p><pre class="brush: php">&lt;br /&gt;
 &lt; ?php&lt;br /&gt;
 $menu = file_get_contents(&quot;menu.html&quot;);&lt;br /&gt;
 $menu = preg_replace(&quot;|
&lt;li&gt;&lt;a href=\&quot;&quot; . basename($_SERVER[&#039;PHP_SELF&#039;]) . &quot;\&quot;&gt;(.*)]+&gt;|U&quot;, &quot;
&lt;li class=\&quot;current\&quot;&gt;$1&lt;/li&gt;
&lt;p&gt;&quot;, $menu);&lt;br /&gt;
 echo $menu;&lt;br /&gt;
 ?&gt;&lt;br /&gt;
 </pre></p>
<p>Just place the PHP snippet within your page wherever you want to display your menu.</p>
<p>What does it do? It simply uses &#8216;preg_replace&#8217; to take your menu, find the link to the current page (basename($_SERVER['PHP_SELF'])), and then remove the &#8216;a&#8217; tags to remove the clickability for the current page (visitors don&#8217;t need to click it because they&#8217;re already there), and give the &#8216;li&#8217; tag a class (&#8217;current&#8217;) and print out the menu on the page. Of course then you can style the &#8216;current&#8217; class in whatever way you choose with CSS. Though the same thing can be done using the cascade and CSS, that involves using extra markup (adding an &#8216;id&#8217; to the body and list (&#8217;li&#8217;) elements), and of course you have to remember to change the body &#8216;id&#8217; for each page, and adding extra markup to the HTML and CSS seems a lot more cumbersome than this nifty little PHP snippet that does the job without any extra effort on your part. That&#8217;s the sort of code I like!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://neonblueweb.co.uk/dreams/2008/02/12/woo-hoo-i-didded-it-and-a-rather-nifty-php-include-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
