简体   繁体   中英

PHP include for header menu footer works on index.php but not other pages

I have tried substituting my html code for include PHP references. It works on the index.php but the three includes, header menu and footer do not appear on the other pages, though the content and spaces are there.

I used the original working index.html to make a copy called index.php and saved this. I chop out the header, menu and footer html code substituting an include instruction each time. I saved these snippets html code as 3 html files. The remaining file contents were saved as a template. Everything is good on the trial on the web hosting site. Header Menu and Footer all display correctly. I used the template then to make other pages, inputting only the text and graphics which all display correctly from the index.php start and I use the browser back button to check other pages. I have checked the original index.php alongside the template to make sure I only removed the content of the 3 files. All the files are in one folder on the host. I am missing something basic, could it be the three files to be included are not given absolute paths?

website is www.crowegenealogy.net for reference?

template code below

<!DOCTYPE html>
<html lang="en">
  <head>
     <title>Crowe Genealogy - Ireland and the World</title>
     <meta http-equiv="content-type" content="text/html; charset=utf-8">
     <link href="css/layout.css" rel="stylesheet" type="text/css">
     <link href="css/menu.css" rel="stylesheet" type="text/css">
  </head>
 <body>
  <?php include 'header.html' ;?> <br>
  <div class="container"><br>
  <ul id="nav">
  <?php include 'menu.html' ;?>
     </ul>
     </div>
     <p><br>
    <?php include 'footer.html' ;?> </p>
  </body>
</html>

SJacks provided the answer and I found it repeated elsewhere, though it doesn't always work. It just proved that a lot of tutorials are academic solutions or part solutions and not real world. PHP is touted on some pages as providing a simple answer to old html sites but the simple road is fraught with more technical problems of construction and implementation, needing a greater understanding of PHP as a whole. Better to go back to first principles and make the new site, canabalising what can be recovered to avoid lengthy, tedious frustration - important when you are being paid?: :)

Your other pages don't work because they're made from HTML files. I clicked on Analysis > Crowe Locations and it took me to http://www.crowegenealogy.net/analysis_1.html (which is an HTML file). The header wasn't working, as you said. So, I pulled up the source code and found that you were trying to use PHP code in there, and that's what's not working. your PHP code isn't being executed because it's in a.php file (and you are not currently employing .htaccess to allow running php code in an html file (see SJacks' comment below). The other answerers and commenters are right that you should be using the.php extension for all these files. It's ok to have a.php file that has only HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM