对网站的所有页面使用通用模板 [英] use common template for all pages of website

查看:29
本文介绍了对网站的所有页面使用通用模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,标题没有多大意义,但这就是我打算做的.我为我的网站设计了一个模板,头部主体和 div 用于特定的东西和一切.该网站由页眉文件、页脚文件、右侧栏、页眉下拉菜单和主体组成,主体将出现在页眉下拉菜单下方、右侧栏左侧和页脚上方.现在有一些内容就是这个主体区域.我想要实现的是,每当点击网页的任何其他部分上的任何链接时,我都希望该内容显示在此主体中.现在我正在将此模板复制到每个页面,但我想将此标准模板保留为 index.php,然后根据单击的链接替换主体内容.这是一个基于php的网站.有什么例子可以让我看到这是如何实现的吗?或者是否有任何标准程序可以做到这一点.请指导我,谢谢.

解决方案

这是一个非常简单的方法:

index.php

<头><title>标题</title><!-- 将样式表、js 文件等放在这里--><身体><!-- 您可以在此处设置导航栏或其他内容--><div class="navbar"><a href="?page=page1">第 1 页</a><a href="?page=page2">第 2 页</a>

<?php putPage($_GET['page']);?><!-- 在此处放置页脚-->

然后将包含内容的 .html 页面放在 html 子文件夹中.脚本将获取它们并将它们插入正文中.

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:

index.php

<?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>

Then just put .html pages with the contents in an html subfolder. The script will fetch them and insert them in the body.

这篇关于对网站的所有页面使用通用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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