正文标题标签(php)
问题描述:
我目前在我的网站页脚有标题标签。 这是因为标题是动态的,如果我把它放在头部,那么它是空白的,因为标题内容直到正文才会被加载。正文标题标签(php)
我的问题是,SEO明智吗,标题标签在页脚而不是标题?
答
我目前在我的网站页脚有标题标签。
这是无效的。标题标签must be in the <head>
section:
每个HTML文档必须必须在
HEAD
节一TITLE
元素。
此外,它可能会给现实世界的问题。我从来没有在页面的页脚中看到title
标签,我预计它们将被搜索引擎忽略。
您应该更改PHP脚本的底层架构,以便在页面启动时知道标题。
参考:
答
"if I place it in the head then it's blank, as the title content doesn't get loaded until the body."
- 这意味着你的网站设计是错误
您应该使用模板和适当的页面布局。
事实上,你的页面代码应该输出什么,但只选通器所需的数据,然后要么抛出错误或致电模板
简明的例子:
称为页links.php
:
<?
//include our settings, connect to database etc.
include dirname($_SERVER['DOCUMENT_ROOT']).'/cfg/settings.php';
//getting required data
$DATA=dbgetarr("SELECT * FROM links");
$pagetitle = "Links to friend sites";
//etc
//and then call a template:
$tpl = "links.php";
include "template.php";
?>
现在template.php
这是您的主要网站模板,由您的页眉和页脚组成:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My site. <?=$pagetitle?></title>
</head>
<body>
<div id="page">
<? include $tpl ?>
</div>
</body>
</html>
和links.php
是实际的页面模板:
<h2><?=$pagetitle?></h2>
<ul>
<? foreach($DATA as $row): ?>
<li><a href="<?=$row['link']?>" target="_blank"><?=$row['name']?></a></li>
<? endforeach ?>
<ul>
简单,干净和维护。
答
我使用了类似于Col的方法,但是这个会将您的文件名称(即my_contact_form.php)并将其更改为“我的联系表单”作为您的页面标题。不完全是你需要的,但我只是想给你另一种选择。
我有一个名为config.php的文件,其中包含我的功能等。
<?php
// dynamic page titles
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page = str_replace('_',' ',$page);
$page = str_replace('.php','',$page);
$page = ucwords($page);
?>
现在我只需要调用的页面包括我想要的标题被替换
<?php require("config.php") ?>
,并使用标题如下
<title>Your Site Name » <?php echo $page; ?></title>
任何页面上是的,它确实很重要。 – 2011-03-13 10:26:04