<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>maspick's blog</title>
  <link rel="alternate" type="text/html" href="http://code2design.com/blog/maspick"/>
  <link rel="self" type="application/atom+xml" href="http://code2design.com/blog/9/atom/feed"/>
  <id>http://code2design.com/blog/9/atom/feed</id>
  <updated>2007-02-09T14:23:05-05:00</updated>
  <entry>
    <title>You Can CMS Without One Two</title>
    <link rel="alternate" type="text/html" href="http://code2design.com/maspick/you_can_cms_without_one_two" />
    <id>http://code2design.com/maspick/you_can_cms_without_one_two</id>
    <published>2007-04-05T16:07:03-04:00</published>
    <updated>2007-04-05T16:17:50-04:00</updated>
    <author>
      <name>maspick</name>
    </author>
    <category term="Maspick" />
    <category term="PHP" />
    <summary type="html"><![CDATA[<p>In my last posting, I demonstrated how to create a header and footer file to be included at the top and bottom of all, or at least many, pages.  This makes it easy to modify those parts and have the changes automatically spread across all the pages that share that header and footer file.  This is one of the things a CMS simplifies for the user.<br />
But what if part of your header, or footer, file is your navigation system and you want the button or link to change when the page associated is chosen?  That means your header, or footer, must change depending on what page it's included on.  Actually, that's one of the beautiful things about PHP - since it's commands are processed prior to the display of the page, you can program those changes to happen for you automatically.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>In my last posting, I demonstrated how to create a header and footer file to be included at the top and bottom of all, or at least many, pages.  This makes it easy to modify those parts and have the changes automatically spread across all the pages that share that header and footer file.  This is one of the things a CMS simplifies for the user.</p>
<p>But what if part of your header, or footer, file is your navigation system and you want the button or link to change when the page associated is chosen?  That means your header, or footer, must <span style="font-style:italic">change</span> depending on what page it's included on.  Actually, that's one of the beautiful things about PHP - since it's commands are processed prior to the display of the page, you can <span style="font-style:italic">program</span> those changes to happen for you automatically.</p>
<p>The first thing we need to do is determine what page is being displayed at the moment.  The following bit of code, placed at the top of your header file so that it's executed first, will get you the page you're on:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />$parts&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">'/'</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$_SERVER</font><font color="#007700">[</font><font color="#DD0000">'PHP_SELF'</font><font color="#007700">]);<br /></font><font color="#0000BB">$this&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">$parts</font><font color="#007700">[</font><font color="#0000BB">count</font><font color="#007700">(</font><font color="#0000BB">$parts</font><font color="#007700">)&nbsp;-&nbsp;</font><font color="#0000BB">1</font><font color="#007700">];<br /></font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$this</font><font color="#007700">,&nbsp;</font><font color="#0000BB">0</font><font color="#007700">,&nbsp;-</font><font color="#0000BB">4</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>What this does is isolate the filename part of the path from the subdirectory(ies) it resides in.  The first command creates an array called parts from whatever is between the slashes ('/') of the path.  The next determines the filename &amp; extension based upon the index value of the last array element.  Finally, we pull off the extension in the third command.  The second and third commands could be combined, but there's a reason I keep them separate that I'll explain in a bit.</p>
<p>Okay, we have the name of the page at our disposal, what do we do with it?  In our navigation, we can now make decisions about what to do when a certain page is loaded.  Here's an example of one navigation element:</p>
<p><div class="codeblock"><code>&lt;div id=&quot;navigation&quot;&gt;<br />&lt;ul&gt;<br />&lt;li<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">if&nbsp;(</font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">==&nbsp;</font><font color="#DD0000">'guestbook'</font><font color="#007700">)&nbsp;echo&nbsp;</font><font color="#DD0000">"&nbsp;class=\"there\""</font><font color="#007700">;&nbsp;</font><font color="#0000BB">?&gt;</font></font>&gt;<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">if&nbsp;(</font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">!=&nbsp;</font><font color="#DD0000">'guestbook'</font><font color="#007700">)&nbsp;{&nbsp;</font><font color="#0000BB">?&gt;</font></font>&lt;a href=&quot;guestbook.php&quot;&gt;<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">}&nbsp;</font><font color="#0000BB">?&gt;</font></font>Guestbook<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">if&nbsp;(</font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">!=&nbsp;</font><font color="#DD0000">'guestbook'</font><font color="#007700">)&nbsp;echo&nbsp;</font><font color="#DD0000">"&lt;/a&gt;"</font><font color="#007700">;&nbsp;</font><font color="#0000BB">?&gt;</font></font>&lt;/li&gt;</code></div></p>
<p>Here's what's happening in this list item.  Before we close the LI tag, we check to see if the page name (<span style="font-style:italic">$pname</span>) matches the page this item links to.  If it does, we add the class named <span style="font-style:italic">there</span> which will invoke different styling for that item to indicate on the item itself we're on that page. What follows is a determination whether or not we need to make this item a link based upon whether the page is loaded or not.</p>
<p>Looks like a lot of typing, but if you have a means of saving blocks of code that you use frequently, you can save off one of these lines and copy it to your header or footer the number of times to match the number of navigation elements you have.  Now you'll have an automatically changing navigation system that'll reflect what page you're on without having to remember to code it on the page itself.  And since it's located in one easy-to-edit place, you can modify it as needed when changes happen to your site and it will be reflected in all the pages.</p>
<p>Another feature I usually add to the footer of pages is the last modified date.  With information we grabbed in the header and the following code, it will automatically be changed as we update a page.</p>
<p><code>page last modified <font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">echo&nbsp;</font><font color="#0000BB">date</font><font color="#007700">(</font><font color="#DD0000">"m/j/y&nbsp;h:i"</font><font color="#007700">,&nbsp;</font><font color="#0000BB">filemtime</font><font color="#007700">(</font><font color="#0000BB">$this</font><font color="#007700">));&nbsp;</font><font color="#0000BB">?&gt;</font></font></code></p>
<p>This prints the modified date of the filename (<span style="font-style:italic">$this</span>), giving the date and time that is stored for that page.  Nothing earth-shattering, but a handy thing that some visitors look at to determine how old the information is on a particular page.</p>
<p>Next time, we'll explore some more ways to employ PHP to make your static <span style="font-style:italic">CMS</span> a little less static seeming.  Till then, happy coding! :^{&gt;</p>
    ]]></content>
  </entry>
  <entry>
    <title>You Can CMS Without One</title>
    <link rel="alternate" type="text/html" href="http://code2design.com/maspick/you_can_cms_without_one" />
    <id>http://code2design.com/maspick/you_can_cms_without_one</id>
    <published>2007-02-09T15:08:00-05:00</published>
    <updated>2007-02-19T11:14:46-05:00</updated>
    <author>
      <name>maspick</name>
    </author>
    <category term="Maspick" />
    <category term="PHP" />
    <summary type="html"><![CDATA[<p>For several years now, I've been creating mini CMS's without realizing it - actually before there was such a term.  It's made all the difference in the world in maintaining websites, especially with over 50 sites like we watch over.  How do I do it?  Thought you'd never ask. :)<br />
This requires either PHP or SSI (Server Side Includes).  I'll be talking about the PHP method here, but can show the other if there's a demand.<br />
First step is to create your first page normally and get it just the way you want it.  Then examine your source to see what will be repeated on the rest of the pages on the top and bottom.<br />
Whatever part of the code will be repeated at the top of each page, remove from your page and paste into a document of it's own called header.php.  The part that will be at the bottom of each page, remove and place in a document called footer.php.  In your original document, put the following in place of the contents of the new header.php:</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>For several years now, I've been creating mini CMS's without realizing it - actually before there was such a term.  It's made all the difference in the world in maintaining websites, especially with over 50 sites like we watch over.  How do I do it?  Thought you'd never ask. :)</p>
<p>This requires either PHP or SSI (Server Side Includes).  I'll be talking about the PHP method here, but can show the other if there's a demand.</p>
<p>First step is to create your first page normally and get it just the way you want it.  Then examine your source to see what will be repeated on the rest of the pages on the top and bottom.</p>
<p>Whatever part of the code will be repeated at the top of each page, remove from your page and paste into a document of it's own called header.php.  The part that will be at the bottom of each page, remove and place in a document called footer.php.  In your original document, put the following in place of the contents of the new header.php:</p>
<p><code><font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">include(</font><font color="#DD0000">"header.php"</font><font color="#007700">);&nbsp;</font><font color="#0000BB">?&gt;</font></font></code></p>
<p>In place of the contents of the new footer.php, put the following:</p>
<p><code><font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">include(</font><font color="#DD0000">"footer.php"</font><font color="#007700">);&nbsp;</font><font color="#0000BB">?&gt;</font></font></code></p>
<p>Here's what you should end up with:<br />
<span style="font-style:italic">Main Document</span><br />
<div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">include(</font><font color="#DD0000">"header.php"</font><font color="#007700">);&nbsp;</font><font color="#0000BB">?&gt;</font></font><br /><br />     . . .<br /><br />     PAGE CONTENTS<br /><br />     . . .<br /><br /><font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">include(</font><font color="#DD0000">"footer.php"</font><font color="#007700">);&nbsp;</font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p><span style="font-style:italic">header.php</span><br />
<div class="codeblock"><code>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br />&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />	&lt;head&gt;<br />		&lt;title&gt;My Site&lt;/title&gt;<br />		&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;<br />		&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; /&gt;<br />	&lt;/head&gt;<br />	&lt;body&gt;<br />		&lt;div id=&quot;container&quot;&gt;</code></div></p>
<p><span style="font-style:italic">footer.php</span><br />
<div class="codeblock"><code>			&lt;div id=&quot;footer&quot;&gt;<br />				&lt;p&gt;© 2007 My Design Company&lt;/p&gt;<br />			&lt;/div&gt;<br />		&lt;/div&gt;<br />	&lt;/body&gt;<br />&lt;/html&gt;</code></div></p>
<p>What this does is allow you to concentrate on the contents of the individual page without weeding through the stuff that's got to be at the top and bottom of each page, which can be extensive depending on the layout.  Also, if you need to tweak something in the top or bottom of the pages, you only have to change it in one place and it's instantly changed across every page that <span style="font-style:italic">includes</span> it.</p>
<p>I hear you saying to yourself, "Well that's cool.  I can see where that might save me some time.  Is that all there is, though?"  Not at all.  In the next installment, I'll share some techniques to make this idea "stand up and dance."  Stay tuned.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Who Am I?</title>
    <link rel="alternate" type="text/html" href="http://code2design.com/maspick/who_am_i" />
    <id>http://code2design.com/maspick/who_am_i</id>
    <published>2007-02-09T14:23:05-05:00</published>
    <updated>2007-02-09T14:23:05-05:00</updated>
    <author>
      <name>maspick</name>
    </author>
    <category term="Maspick" />
    <summary type="html"><![CDATA[<p>I'm Tom ('Mas) Pickering.  You can call me anything but late to supper. :)</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>I'm Tom ('Mas) Pickering.  You can call me anything but late to supper. :)</p>
<p>I've been involved with computer since the early 70's, a time when it took large, climate-controlled rooms to provide the power contained in a desktop machine from within the last decade.</p>
<p>For the last 12 years, my wife and I (we met online, BTW) have run our own web design business.  She's the designer and I'm the geek.  I specialize in coding in XHTML/CSS &amp; PHP/MySQL.  I hope to share with y'all some of the insights i've collected over years of programming in general and for the web more specifically.</p>
    ]]></content>
  </entry>
</feed>
<!-- Rendered in 0.36732 -->