Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a few different ways to do this that are all more-or-less equal. I almost always use a config.php file for sites to hold whatever global information I want every page to have. At the top of every page, you just call</p> <pre><code>&lt;?php require_once('config.php'); ?&gt; </code></pre> <p>In that config.php file, you could have an array listing your page names and the file you want included for each page, as well as a function that returns the content, like so:</p> <pre><code>// this lets you call includes relative to the site root set_include_path($_SERVER['DOCUMENT_ROOT']); $defaultAsideContent = 'includes/default.php'; $asideContent = array( 'index.php' =&gt; 'includes/include-1.php', 'document.php' =&gt; 'includes/include-2.php' ); function getAsideContent() { global $asideContent; global $defaultAsideContent; $content = $defaultAsideContent; // get the requested page $pageFull = $_SERVER['REQUEST_URI']; // strip URL variables $pageParts = explode('?', $pageFull); $page = $pageParts[0]; // loop throught the array and see if there is specific aside content for the page foreach($asideContent as $key=&gt;$value) { if ($page == $key) { $content = $asideContent[$key]); } } include($content); } </code></pre> <p>Lastly, wherever you want your aside content to show up, just do</p> <pre><code>&lt;?php getAsideContent(); ?&gt; </code></pre> <p>When you create a new page, if you want specific aside content, just edit your config file. Just FYI, didn't test this at all, probably has bugs, but you get the jist.</p>
 

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