根据单页面模板结构,只有一个名为index.php
的文件在其中使用PHP函数include_once()
将页面嵌入到查询字符串$_GET['page']
如何在一个页面模板中设置动态标题,在主体标签中嵌入不同的页面 - PHP
<?php $page = $_GET['page']; ?>
<html>
<head>
<title>
<!-- title needs to update according to page here -->
</title>
</head>
<body>
<?php require_once MC_ROOT.'/pages/'.$page.'.php'; // page content goes here like: <div> [CONTENT], <h1> [PRODUCT TITLE] </h1> </div> etc... ?>
</body>
</html>
如何设置其内部到来之前为每个页面<title></title>
标签动态标题?页面应该是home, product, contact, about
等请建议任何最佳做法。谢谢
添加参数来获取? – hardworker
实际上网址类似于:'/index.php?page=home'或'index.php?page = product'或'/index.php?page=gear'。每个页面都嵌入到从index查询字符串中获取值的index.php文件的主体标签中。看起来很简单,但我猜结构不好。 – RanaHaroon
您可以添加一个像/index.php?page=home&title=test的参数吗?然后,您可以获取页面的“动态”标题。或者你可以用javascript做,在页面中设置一个隐藏的html标签,然后用隐藏的html标签内容修改标题 – hardworker