2016-05-22 11 views
0

ウェブサイトには、ヘッダー、ナビゲーションバー、フッターなどの共通要素が含まれています。私のページに共通する静的なHTML要素が同じPHPスクリプトから供給されるように、HTMLページをどのように書き直すべきですか?いくつかの例を教えてもらえますか?私のhtmlページのPHPを使用してWebサイトの共通要素を再利用する(HTML)

例:

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <meta charset="utf-8" /> 
 
    <meta name="description" content="example" /> 
 
    <meta name="keywords" content="HTML5 PHP" /> 
 
    <meta name="author" content="Detonizer" /> 
 
    <title>Home</title> 
 
</head> 
 

 
<body> 
 
    
 
    <nav> 
 
     <p class="menu"><a href="page1.html">page1</a></p> 
 
\t \t <p class="menu"><a href="page2.html">page2</a></p> 
 
\t \t <p class="menu"><a href="page3.html">page3</a></p> 
 
\t \t <p class="menu"><a href="page4.html">page4</a></p> 
 
\t \t <p class="menu"><a href="page5.html">page5</a></p> 
 
     <p class="menu"><a href="page6.html">page6</a></p> 
 
\t </nav> 
 
    
 
    <footer class="footC" > 
 
\t \t <p class="e1">Example1</p> 
 
\t \t <p class="e2">Example2</p> 
 
\t \t <p class="e3">Example3</p> 
 
    </footer> 
 
    
 
</body> 
 
</html> 
 
    
 

答えて

1

あなたは、このような異なるファイルをindex.phpファイルを定義し、異なる部分を含めることができます。

<!DOCTYPE html> 
     <html lang="en"> 
      <head> 
       <meta charset="utf-8" /> 
       <meta name="description" content="example" /> 
       <meta name="keywords" content="HTML5 PHP" /> 
       <meta name="author" content="Detonizer" /> 
       <title><?php include 'title.php'; ?></title> 
      </head> 

      <body> 

        <nav> 
         <p class="menu"><a href="page1.html">page1</a></p> 
         <p class="menu"><a href="page2.html">page2</a></p> 
         <p class="menu"><a href="page3.html">page3</a></p> 
         <p class="menu"><a href="page4.html">page4</a></p> 
         <p class="menu"><a href="page5.html">page5</a></p> 
    <p class="menu"><a href="page6.html">page6</a></p> 
        </nav> 
        <section id="content"> 
         <?php include 'content.php'; ?> 
        </section> 
        <footer class="footC" > 
         <p class="e1">Example1</p> 
         <p class="e2">Example2</p> 
         <p class="e3">Example3</p> 
        </footer> 

      </body> 
      </html> 
0

このを呼び出しheader.php

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="description" content="example" /> 
    <meta name="keywords" content="HTML5 PHP" /> 
    <meta name="author" content="Detonizer" /> 
    <title>Home</title> 
</head> 

コールあなたPHPページでこのfooter.php

<footer class="footC" > 
    <p class="e1">Example1</p> 
    <p class="e2">Example2</p> 
    <p class="e3">Example3</p> 
</footer> 

<?php include_once 'header.php'; ?> 
<body> 
    <nav> 
     <p class="menu"><a href="page1.html">page1</a></p> 
     <p class="menu"><a href="page2.html">page2</a></p> 
     <p class="menu"><a href="page3.html">page3</a></p> 
     <p class="menu"><a href="page4.html">page4</a></p> 
     <p class="menu"><a href="page5.html">page5</a></p> 
     <p class="menu"><a href="page6.html">page6</a></p> 
    </nav> 
<?php include_once 'footer.php'; ?> 
</body> 
</html> 
関連する問題