PHP 将页面生成的标题放入中
我们在网站的所有页面上都包含一个 header.php 文件。因此,我们可以在 header.php 文件中放置一个标题,该标题将应用于整个站点,或者在每个页面中添加一个自定义标题以更具描述性。
问题是,这样做时,标题将位于 head 标签之外(保留在 header.php 文件中)并被标记为无效。
我们是否可以使用某种函数在页面内定义一个变量($pageTitle),该变量将显示在 head 标签中?
谢谢。
We include a header.php file across all the pages on our site. So we could either place a single title in the header.php file which would be applied to the entire site, or have a custom header within each page to be more descriptive.
The problem is that in doing that, the title would be outside the head tags (which remain in the header.php file) and marked as invalid.
Is there some kind of function we can use to define a variable ($pageTitle) within the page, that will be displayed in head tag?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
其实应该是这样的
news.php:
template.php:
tpl.news.php
简单明了
Actually it should be this way
news.php:
template.php:
tpl.news.php
plain and simple
嗯......
编辑
然后在你的 header.php 中
Ummm.....
EDIT
Then in your header.php
看起来您想要在某些页面上使用动态标题?
It looks like you want a dynamic title on some pages?
在我看来,您仍然可以在标头中完成所有这些工作:
header.php 就这样结束了。现在,将其包含在您想要使用它的每个页面上,然后添加您的
。
只是一个想法,但无论如何你要解决这个问题,你必须首先连接到你的数据库,检查页面是否存在,如果存在,则将标题设置为变量,然后开始构建 html。
The way I see it, you can still do all this work in your header:
Thus concludes you header.php. Now include this on every page you want to use it, and follow with your
<body></body></html>
.Just one idea, but anyway you go around this, you're going to have to connect to your DB first, check if page exists, if so set title as variable, then begin constructing html.