我有单页没有页眉/页脚。他们只是每个页面的内容。设置页面标题后<head>标签
我的index.php页面有围绕页面标题的模板,但我想在每个页面中设置每个页面标题。
在index.php网页,我包括在<body>
标签
我有单页没有页眉/页脚。他们只是每个页面的内容。设置页面标题后<head>标签
我的index.php页面有围绕页面标题的模板,但我想在每个页面中设置每个页面标题。
在index.php网页,我包括在<body>
标签
我有一种替代方法可能是有用的页面文件。
不要关闭索引文件中的头标签,然后在内容文件中使用标签设置标题并关闭头标签。
像
的index.php
<html>
<head>
<!--links--->
<?php require "content.php";?>
</html>
content.php文件:
<title>YOUR TITLE</title>
</head>
<body>
<!--your data-->
</body>
您可以使用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说能否正常工作以及
另一种解决方案
你可以做到这一点
的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";
}
?>
嗯,好的想法,但它不能正常工作 – charlie
对我来说完美的作品,什么对你不起作用? –