Web design portfolio - LIGHTENING YOUR WORKLOAD WITH INCLUDES 6. Open index.php,

LIGHTENING YOUR WORKLOAD WITH INCLUDES 6. Open index.php, and insert the following in the space left by the nav unordered list: 7. Save index.php and load the page into a browser. It should look exactly the same as before. Although the menu and the rest of the page are coming from different files, PHP merges them before sending any output to the browser. 8. Do the same with the footer

. Cut the lines highlighted in bold in the origi nal listing, and paste them into a blank file called footer.inc.php in the includes folder. Then insert the command to include the new file in the gap left by the footer
: 9. Save all pages and load index.php into a browser. Again, it should look identical to the original page. If you navigate to other pages in the site, the menu and footer should appear on every page. The code in the include files is now serving all pages. 10. To prove that the menu is being drawn from a single file, change one of the links in menu.inc.php like this, for example:
  • Blog
  • 11. Save menu.inc.php and view the site again. The change is reflected on all pages. You can check your code against index02.php, menu.inc01.php, and footer.inc01.php. As Figure 4-2 shows, there s a problem with the code at the moment. Even when you navigate away from the home page, the style that indicates which page you re on doesn t change (it s controlled by the here ID in the tag). Fortunately, that s easily fixed with a little PHP conditional logic. Figure 4-2. Moving the navigation menu to an external file makes maintenance easier, but you need some conditional logic to apply the correct style to the current page. Before doing that, let s take a look at some important aspects of working with include files in PHP.
    We recommend you use
    shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

    Leave a Reply