2017-04-21 76 views
0

我有單頁沒有頁眉/頁腳。他們只是每個頁面的內容。設置頁面標題後<head>標籤

我的index.php頁面有圍繞頁面標題的模板,但我想在每個頁面中設置每個頁面標題。

在index.php網頁,我包括在<body>標籤

回答

1

我有一種替代方法可能是有用的頁面文件。

不要關閉索引文件中的頭標籤,然後在內容文件中使用標籤設置標題並關閉頭標籤。

的index.php

<html> 
<head> 
<!--links---> 
<?php require "content.php";?> 
</html> 

content.php文件:

<title>YOUR TITLE</title> 
</head> 
<body> 
<!--your data--> 
</body> 
0

您可以使用JavaScript或者jQuery來做到這一點。 首先,給標題踏歌一個id

<title id='page_title'>My Page</title> 

然後在每個頁面上,只是在放像:

<script> 
    var new_page_title= 'My New Title' 
</script> 

最後在模板的頁腳部分,只需使用JavaScript或jQuery來更改名稱:

// javascript 
document.getElementById ('page_title').innerHTML = new_page_title; 

// jquery 
$ ('#page_title').html (new_page_title); 

編輯

什麼@Purushotam說能否正常工作以及

0

另一種解決方案

你可以做到這一點

的index.php

<html> 
<head> 
<title><?php title_func(); ?></title> 
</head> 

<body> 
require "content.php"; 
</body> 
</html> 

content.php 只是使這種功能的任何地方

<?php 
    function title_func(){ 
     echo "title here"; 
    } 
?> 
+0

嗯,好的想法,但它不能正常工作 – charlie

+0

對我來說完美的作品,什麼對你不起作用? –