ale*_*nco 2 html php variables
我基本上使用php变量来存储标题的值和正文的ID.最后一种是根据用户所在页面的哪一部分在导航中按下(按下)按钮的技术(在这种情况下,用户将知道他当前处于"家").
我的开始index.php:
<?php
$title = "New Project";
$body = "home";
include("common/header.php");
?>
<div id="content">
<div class="container">
<div id="tagline">
Run Code Online (Sandbox Code Playgroud)
我的header.php的开头
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="styles/slimbox2.css" />
<link rel="stylesheet" type="text/css" href="styles/global.css" />
<link rel="stylesheet" type="text/css" href="styles/home.css" />
<link rel="stylesheet" type="text/css" href="styles/contact.css" />
<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="scripts/jquery.corner.js"></script>
<script type="text/javascript" src="scripts/jquery.validate.js"></script>
<script type="text/javascript" src="scripts/slimbox2.js"></script>
<script type="text/javascript" src="scripts/custom.js"></script>
</head>
</head>
<body id="<?php echo $body; ?>">
<div id="header">
<div class="container">
<div id="topbar">
<h1><a href="http://widerdesign.co.nr/">wider design</a></h1>
<ul id="lang">
<li><a href="index.php">English</a></li>
<li><a href="es/index.php">Español</a></li>
<li><a href="tw/index.php">??(??)</a></li>
<li><a href="cn/index.php">??(??)</a></li>
</ul>
<ul id="nav">
<li class="home"><a href="index.php">home</a></li>
<li class="products"><a href="products.php">products</a></li>
<li class="about"><a href="about.php">about</a></li>
<li class="contact"><a href="contact.php">contact</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
让用户知道他/她在哪个部分:
#home li.home a, #products li.products a, #contact li.contact {
color: #999;
}
Run Code Online (Sandbox Code Playgroud)
有一种更简单的方法吗?
我是否使用了不必要的那些PHP变量?
是的,你正在做的事情很好.我使用PageTemplate类做类似的事情.除了设置标题和导航外,它还允许基于用户身份验证显示导航链接,允许将javascript和css添加到头部等.
你正在做的事情非常普遍.有一百万种方法可以做到,但它们都需要设置一些变量.