I have a template, written in PHP, and I have a series of links to certain pages in my site. I am aware that PHP allows you to "include" pages using the include tag, but how do I control which page to include using a link?
Also, do all of the pages that I want to include need to be saved as a PHP format, or can I insert HTML pages just the same?
Worst case scenario, I will need to create a HTML template in Dreamweaver and edit my pages using that instead. I hope that the PHP include is quicker.
How do I include a PHP (or even HTML) page into into my PHP template when I click a link?
You can do it in a few different ways:
%26lt;?php include("menu.php"); ?%26gt;
%26lt;?php include_once("menu.php"); ?%26gt;
OR..
%26lt;?php require("menu.php"); ?%26gt;
%26lt;?php require_once("menu.php"); ?%26gt;
Let me explain the difference:
If using include or include_once can throw a parse error if the the direction to the file is not corrrect.
If using require or require once, if the the direction to the file is not corrrect you will get a fatal error.
Reply:Using PHP's include function, you can include what you want. It doesn't have to be .php or .html. For example, all of my includes are named as such: header.inc and they work just fine.
As for the execution ... let's say you have a navigation menu that you want to include on the left side of every page. Just start everypage like this:
%26lt;?php
include("includes/nav.inc");
?%26gt;
This is assuming that you have your directory structure like this:
root/index.php (the page using the include function)
root/includes/nav.inc (the include file that you want to use)
The huge benefit to using includes is that you can change only one file, and it cascades throughout your entire site, because all pages merely reference that file.
Good luck!
business cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment