Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like Andrew said, use <a href="http://php.net/manual/en/function.include.php" rel="nofollow">include</a>s. I'll set up 2 basic examples.</p> <hr> <p>The simplest, have multiple layout files that are called by your main file(s):</p> <p>header.php:</p> <pre><code>&lt;div id="header"&gt; Menu can go here. &lt;?php echo 'I make all my files .php, so they can use PHP functions if needed.'; ?&gt; &lt;/div&gt; </code></pre> <p>footer.php</p> <pre><code>&lt;div id="footer"&gt; &lt;a href="#"&gt;Footer Link&lt;/a&gt; &lt;/div&gt; </code></pre> <p>index.php</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;?php include('/path/to/header.php'); ?&gt; Specific index.php content here. &lt;?php include('/path/to/footer.php'); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <hr> <p>The other option is to have one PHP file which includes all your different layout elements in functions. The reason I like this, is because you can include one file and then call specific functions for different parts. This can also be used to pass variables like a title of a page.</p> <p>layout.php</p> <pre><code>&lt;?php function makeHeader($title) { return 'My title is: '.$title; } function makeFooter() { $html = ' &lt;div id="footer"&gt; &lt;a href="#"&gt;Footer Link&lt;/a&gt; &lt;/div&gt; '; return $html; } ?&gt; </code></pre> <p>index.php</p> <pre><code>&lt;?php include('/path/to/include.php'); ?&gt; &lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;?php echo makeHeader('Page Title'); ?&gt; Specific index.php content here. &lt;?php echo makeFooter(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <hr> <p>Just make sure you use relative paths (<code>no http://www.</code>) when including files. This will allow variables and functions to transfer over smoothly. The easiest way to do this is using the PHP variable <code>$_SERVER['DOCUMENT_ROOT']</code> so if you have a file <a href="http://mysite.com/includes/layout.php" rel="nofollow">http://mysite.com/includes/layout.php</a>, you could include it with <code>include($_SERVER['DOCUMENT_ROOT'].'/includes/layout.php')</code> no matter where your file you are including from is located.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload