使用通用模板网站的所有网页 [英] use common template for all pages of website
问题描述
OK,标题并没有多大意义,但是这正是我打算做的事。我设计我的网站模板,头部和身体的股利具体的东西和一切。该网站包含头文件,页脚文件,右侧栏,标题下拉菜单和主体这将是头下拉菜单下方present,以右侧栏的左侧,而页脚以上。现在有一些内容是此主体区域。我试图实现的是只要单击任何网页的其他部分的任何一个环节,我想,内容在这个主体来显示。现在我复制此模板每个页面,但我想保持这个标准模板的index.php,然后替换基于链接的主体内容点击。这是一个基于PHP的网站。是否有任何的例子在那里我可以看到如何实现这一点?或者有没有标准程序来做到这一点。请指导我,谢谢。
ok, the title did not make much sense but this is what i am planning to do. I have designed a template for my website, with head body and div for specific stuff and everything. The website consists of header file, footer file, right-side column, header dropdown menu and a main body which would be present beneath the header dropdown menu, to the left of the right-side column, and above the footer. Right now there is some content is this main body area. What i am trying to achieve is that whenever any link is clicked on any of the other parts of the webpage, i want that content to be displayed in this main body. Right now i am copying this template to each and every page, but I want to keep this standard template as index.php and then replace main body content based on the link clicked. This is a php based website. Are there any examples where i can see how this can be achieved? or is there any standard procedure to do this. Please guide me, Thanks.
推荐答案
下面是一个非常简单的方法来做到这一点:
Here's a very simple way to do this:
<?php
function putPage($page) {
// put a list of allowed pages here
$allowed = array('page1', 'page2');
$page = trim($page);
$page = (in_array($page, $allowed)) ? $page : 'home';
echo @file_get_contents('.\html\\' . $page . '.html');
}
?>
<html>
<head>
<title>Title</title>
<!-- put stylesheets, js files, etc. here -->
</head>
<body>
<!-- you can have a nav bar or something here -->
<div class="navbar">
<a href="?page=page1">Page 1</a> <a href="?page=page2">Page 2</a>
</div>
<?php putPage($_GET['page']); ?>
<!-- put a footer here -->
</body>
</html>
然后只要把与内容的.html页面在一个HTML子文件夹。
该脚本将获取它们在体内插入。
Then just put .html pages with the contents in an html subfolder. The script will fetch them and insert them in the body.
这篇关于使用通用模板网站的所有网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!