
I regularly make scripts available for download to help people put dynamic content on their site. My scripts are intended for "newbie" webmasters, people without much PHP knowledge, or people without much time to "reinvent the wheel" for simple functionality.
The goal - always - is to make it possible for you to completely integrate my script into your site's design. One of my biggest complaints about other scripts out there is that they all seem to want to dictate the way their script looks on your site. I feel differently. I want my script to look like you made it. I want it to look like your site. The only downside to this is that you have to know how to make a "template", using PHP's include() function. The tutorial below will show you how.
Throughout this example, I am going to be using a tables-based page as an example, only because it is easier to understand.
Let's pretend that your site has a 3 column layout with a header and a footer, like so:
| TOP | ||
| L E F T | CONTENT | R I G H T |
| BOTTOM | ||
If you're at all familiar with HTML, you know that the stuff at the top of your HTML document is the stuff that shows up at the top of the screen and the stuff at the bottom of the HTML document is the stuff that shows up at the bottom of the screen. That part is obvious. But for some reason, what tends to trouble some newbies is the middle part. Well, that's actually pretty straight forward, too. The stuff in the middle goes from left to right.
So let's review the order in which things come in an HTML document:
This is where the magic comes in behind how I make my script look like your site:
The ONLY thing that I concern myself with is the "content" section! The rest is up to you, through the creation of "header" and "footer" files.
Let's use the following HTML page as our starting point:
Here we see an extremely simple example, but it will demonstrate what I'm talking about pretty easily. The above is just basic HTML. Let's make our header and footer files.
Let's take:
as our header file. Save it as "header.php"
Then, let's take:
as our footer file. Save it as "footer.php".
Now, let's open a new file and enter the following:
Now, save everything above as "page.php" and upload it to a PHP-enabled server! Open it in your browser and you'll see the page. Right-click on your browser window to "view source" and you can see that the entire HTML is now in your page just like it would have been if you uploaded it in static form.
If you see the PHP code instead of the HTML, that means you DO NOT have PHP on your server.
The above demonstrates how you can use PHP to include stuff. But let's look at a more complex example, such as our 3-column layout above. Here's the HTML:
Now, to make our PHP wrapper/ template, we're going to put everything DOWN TO, but not including, the CONTENT cell in the "header.php" file. Then, we're going to put everything UNDER the CONTENT cell in the "footer.php" file.
header.php:
footer.php:
Our new page:
Now, if you upload the new page, you'll see that your page is all put together just like our first example!
Now, take a look at your site. If you're like 99% of the people out there, you have a portion of your web site which always stays the same, such as a logo at the top, maybe some navigation at the top or left, and so on. Then, on every page of your site, you have a content area. You can translate what we've learned above very easily.
There's a lot more that can be said about how you can use PHP's include() function to make your site better and easier to maintain. For now though, you've come to understand how to include shared content in your pages, and how doing so will help integrate my scripts into your site.
None.
Contact Us to see how Web Access Strategies can help your organization.