Sie sind auf Seite 1von 2

Dynamic Inclusion subpages

I merged the dynamic inclusion tutorial and Codegrrl's ConvertToPHP script. You will need to understand dynamic inclusions first. See dynamic subpages in action. If you're already using dynamic inclusion and want to use more, here is a solution. For example, you've already used the dynamic inclusion, so your url look like: index.php?y=page but you want to separate the page into subpages. You won't need your index.php or defaut.php/main.php here, but the page you want to divide. Let's call it page.php, you won't need any:
<!DOCTYPE> <html> <head> <title>your title</title> </head> <body> // CONTENTS </body> </html>

Since it's already in your index.php... open page.php, the page you want to divide and let the fun begin, paste this in the very first lines, this is your menu to navigate between the subpages.
<h1>Page title</h1> <p>Select: <a href="index.php?y=page">back</a> <a href="index.php?y=page&x=1">link <a href="index.php?y=page&x=2">link <a href="index.php?y=page&x=3">link </p>

| 1</a> | 2</a> | 3</a> |

A few explanations... If your document name is random.php, replace page by random, of course. The x means the link will look like: index.php?y=random&x=value. Now paste this:
<?php if(!$x) { ?>

Of course if you changed x by something else, don't forget to change it. Everything under that line will show up automatically if you go to index.php?y=page. Add the contents you want and when you're done, we will make the contents of link 1. Paste this after your default contents:

<? } elseif ($x == "1") { ?>

Once again, if you replaced x by something else, don't forget to replace it here too. The 1 can be replaced by anything you want, just don't forget to change it in your menu too. Add your contents after that line of code. If you go to index.php?y=page, it won't show up but if you access index.php?y=page&x=1, you will see these contents. When you're done adding the contents of this page, add this line:
<? } elseif ($x == "2") { ?>

Same as previously, add your contents for the second page under that line of code. It will be accessible here: index.php?y=page&x=2. A bit lost? This is what you should have in your page.php
<h1>Page title</h1> <p>Select: <a href="index.php?y=page">back</a> | <a href="index.php?y=page&x=1">link 1</a> | <a href="index.php?y=page&x=2">link 2</a> | <a href="index.php?y=page&x=3">link 3</a> | </p> <?php if(!$x) { ?> <!-- introduction contents, shows up when accessing index.php?y=page --> <? } elseif ($x == "1") { ?> <!-- link1 contents, shows up when accessing index.php?y=page&x=1 --> <? } elseif ($x == "2") { ?> <!-- link2 contents, shows up when accessing index.php?y=page&x=2 --> <? } elseif ($x == "3") { ?> <!-- link3 contents, shows up when accessing index.php?y=page&x=3 --> <? } ?>

Did you notice the <? } ?> ? You will have to add this little code at the end of your page. You can have more than 3 subpages of course, each time your just have to add:
<? } elseif ($x == "SUBPAGE") { ?> <!-- PAGE contents, show up when accessing index.php?y=page&x=SUBPAGE -->

Hope it's understandable! Don't forget you have to use dynamic inclusions first!

Das könnte Ihnen auch gefallen