在PHP中动态更改页面标题 [英] Change Page title dynamically in PHP

查看:67
本文介绍了在PHP中动态更改页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我用PHP创建了一个简单的网站。我正在使用topnav,header,menu,sidebar和footer的include函数。

现在,我有几个问题:

1.当我点击任何菜单项我的页面标题在所有页面上都是相同的。

2.我想更改所选菜单项的背景颜色(我可以使用CSS,但如果不使用包含功能)。

代码如下:

TOP nav.php

Hello everyone
I have created a simple website in PHP. I am using include functions for topnav,header,menu,sidebar and footer.
Now, i am having couple of issues in that:
1. Whenver I click on any menu item the title of my page is all the same on all pages.
2. I wanted to change the background color of the selected menu item (I am able to do it using CSS but if not using include funtions).
The code is like:
TOP nav.php

<br />
<pre lang="xml"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><br />
<html><br />
<head><br />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"><br />
<title>My title goes here!</title><br />
<br />
<link rel="stylesheet" type="text/css" href="style/style.css"><br />
<br />
</head><br />
<body><br />
<div id="wrapper"><br />
    <div id="topbar"><br />
        <div class="date"><?php echo  date("l jS \of F Y ");?></div><br />
        <ul class="topnav"><br />
<br />
                <li><a href="#">About us</a></li><br />
                <li><a href="contact.php">Contact us</a></li><br />
            </ul><br />
<br />
    </div></pre><br />



因为我的所有html部分如标题描述等都保存在topnav.php中,所以我无法更改索引上的标题。 php等等。

请指导我需要编写代码的文件,例如


Since all my html part like title description etc are saved in topnav.php, i am not able to change the title on index.php and so on.
Please guide like on which file i need to write the code like

<br />
<pre lang="php"><?php<br />
$title="";<br />
switch ($title){<br />
case "index.php":<br />
 $title= "index title here";<br />
<br />
 break;<br />
<br />
case  "about.php":<br />
 $title= "about title here";<br />
<br />
 break;<br />
}<br />
<br />
?></pre><br />
<br />

推荐答案

title =;< br />
switch(
title="";<br /> switch (


title){< br />
caseindex.php:< br />
title){<br /> case "index.php":<br />


title =index title here;< br />
< br / >
break;< br />
< br />
caseabout.php:< br />
title= "index title here";<br /> <br /> break;<br /> <br /> case "about.php":<br />


这篇关于在PHP中动态更改页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆