开发者

Adding a new page to a website

开发者 https://www.devze.com 2023-04-10 05:00 出处:网络
sorry if this question seems a bit open ended, but I\'m often wanting to add new pages to my website. As my website grows, this means I\'m having go back and add a link to the new page on all of my pr

sorry if this question seems a bit open ended, but I'm often wanting to add new pages to my website. As my website grows, this means I'm having go back and add a link to the new page on all of my previous pages, which is becoming increasingly time consuming. Is there any way around this? An automatic method? Obviously in an ideal world you'd开发者_高级运维 get the template page correct first, but this doesn't seem to allow for easy expansion. How do the big sites cope? Thanks.


You user server-side includes.

In PHP there are include() and require()

include('filename.php') will add the contents of 'filename.php' to the page it was included on. Require does the same thing, but the script stops if it can't locate or use the file.

Instead of doing:

<div id="navbar" >
    <ul>
        <li>Menu</li>
        <li>item</li>
        <li>item</li>
        <li>item</li>
    </ul>
</div>

Put it in a file called "navbar.html" and just do:

<?PHP include('navbar.html'); ?>

In your include file you could have:

<div id="navbar" >
    <ul>
        <li id="1" class="<?PHP echo $m1class ?>">Menu</li>
        <li id="2" class="<?PHP echo $m2class ?>">item</li>
        <li id="3" class="<?PHP echo $m3class ?>">item</li>
        <li id="4" class="<?PHP echo $m4class ?>">item</li>
    </ul>
</div>

And then in the PHP file:

<?PHP
    $m1class=$m2class=$m4class="notCurrent";
    $m3class="current";
    include('navbar.php');
?>

It would be the same as doing:

<?PHP
        $m1class=$m2class=$m4class="notCurrent";
        $m3class="current";
        include('navbar.php');
?>
<div id="navbar" >
        <ul>
            <li id="1" class="<?PHP echo $m1class ?>">Menu</li>
            <li id="2" class="<?PHP echo $m2class ?>">item</li>
            <li id="3" class="<?PHP echo $m3class ?>">item</li>
            <li id="4" class="<?PHP echo $m4class ?>">item</li>
        </ul>
</div>

...except that you can change the include file so that it changes every page. The output of either would be:

<div id="navbar">
        <ul>
            <li id="1" class="notCurrent">Menu</li>
            <li id="2" class="notCurrent">item</li>
            <li id="3" class="current">item</li>
            <li id="4" class="notCurrent">item</li>
        </ul>
</div>

Goodluck!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号