向网站添加新页面

发布于 2024-12-07 21:22:41 字数 168 浏览 0 评论 0原文

很抱歉,如果这个问题看起来有点开放式,但我经常想向我的网站添加新页面。随着我的网站不断发展,这意味着我必须返回并在之前的所有页面上添加指向新页面的链接,这变得越来越耗时。有什么办法解决这个问题吗?自动方法?显然,在理想的情况下,您首先会获得正确的模板页面,但这似乎不允许轻松扩展。大型网站如何应对?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2024-12-14 21:22:41

您的用户服务器端包含。

PHP 中有 include()require()

include('filename.php') 会添加 'filename.php' 的内容到包含它的页面。 Require 执行相同的操作,但如果无法找到或使用该文件,脚本就会停止。

而不是这样做:

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

将其放入名为“navbar.html”的文件中,然后执行:

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

在包含文件中,您可以:

<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>

然后在 PHP 文件中:

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

与执行相同:

<?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>

...除了您可以更改包含文件,以便它更改每一页。两者的输出都是:

<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!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文