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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号