我试图通过PHP动态设置我的页面标题。我的页面标题位于每个页面上包含的head.php文件中,因此单独执行此操作不是一种选择。动态页面标题通过PHP
我写了下面的代码,我不明白为什么它不工作:
<?php
$currentUrl = $_SERVER['SERVER_NAME'];
$currentpage = $_SERVER["SCRIPT_NAME"];
if("hoosiermommapcs.com"==$currentUrl) {
$currentTitle = "Home";
}
else if("/index.php"==$currentpage) {
$currentTitle = "Home";
}
else if("/dispatch.php"==$currentpage) {
$currentTitle = "Request Pilot Cars";
}
else if("/invoice.php"==$currentpage) {
$currentTitle = "Submit Invoice";
}
else if("/gallery.php"==$currentpage) {
$currentTitle = "Image Gallery";
}
else if("/contact.php"==$currentpage) {
$currentTitle = "Contact Us";
}
$siteTitle = "Hoosier Momma Pilot Car Services | ";
?>
我的页面标题代码:
<title><?php echo($siteTitle . $currentTitle); ?></title>
代码工作设置“家”,而不是在任何其他人。如果我去invoice.php它仍然会在标题中显示“Home”。
任何帮助表示赞赏。
'开关($ _ SERVER [“SCRIPT_NAME”]){}'是理想的选择。 – Devon
直到现在还没有想到使用开关盒功能。可以尝试。谢谢。 –
我从标题中删除了已解决。接受答案会自动将其标记为正在解决。发布自己的答案,接受给定的答案或(标记)删除问题。 –