douxian1939 2016-02-19 13:31
浏览 39
已采纳

如何更改网站中的许多网页?

I am making website and this website will have more than 20pages. I am using my template to add a webpage. This template has header and footer, so I just add the body of new page. But, what if I want to change navigation bar in the header, then I have to change all 20 pages that I already made to correct. I want to know better way. I read a book, and it says about "php include" function. Should I use this function in the header and footer of each webpage to call header and footer file? If I want to change the navigation bar in the header, all I can do is changing only one header file, then rest of website will be changed.

Is this correct way? In this case, what do you do? I am a beginner, so please advise me. Thank you in advance.

  • 写回答

4条回答 默认 最新

  • douhanzhen8927 2016-02-19 13:43
    关注

    You should build your website as following. The header.html would contain the navigation.

    header.html

    <!doctype html>
    <html>
        <head>
            ...
        </head>
        <body>
            <nav>
               ...
            </nav>
    

    footer.html

            <footer>
            ...
            </footer>
        </body>
    </html>
    

    page.php

    <?php
       require_once 'header.html';
    ?>
    
    Your content goes here
    
    <?php
       require_once 'footer.html';
    ?>
    

    You should use require_once so the header and footer will be imported only once per script and if the header or footer cant be found, the script will throw an exception and stop the "application".

    "require_once" and "require" are language constructs and not functions. Therefore they should be written without "()" brackets!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度