如何使常见的页眉和页脚..大问题? [英] how to make common header and footer .. big problem?

查看:112
本文介绍了如何使常见的页眉和页脚..大问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个严重的问题:经过很长时间,我决定我不能解决这个可怕的问题,并在某处寻找帮助。这里是我想问的。



我说我正在运行webiste:xyx.com(apache,php,mysql)所有页面一样.php没有html。



没有这样的文件夹结构/:root,/ abc:root中的另一个文件夹:root和/ abc都有php页面,包括页眉和页脚。页眉和页脚包含一些网址,例如首页,服务,关于我们等。



所以我不得不复制相同的页眉和页脚与它的图像文件夹在根和/它工作。现在我有问题,每当我必须改变的东西,我必须改变在这两个地方。问题不是真的两个文件夹如果我要做更多的文件夹,那么我会注定要做小的改变,我必须改变每个地方。现在如果我做一个公共的页眉和页脚和使用include(),然后我面临的问题由于头包括css,javascript和从/ abc文件夹路径将是不同的让我说,即使我管理这通过php使用if条件仍然不会工作cuz css有自己这么多的图像作为样式。现在我不能改变css,因为这将是一个问题,我不想要两个版本的css,这将影响加载时间。我已经把重负载在网站上,这给我平均加载时间6秒,这太慢了。我希望我能够传达你们谁读这篇文章的人。如果没有,请发帖查询我会回复你。



感谢万分之一:)



现在我的问题是我想有一个共同的页眉和页脚

我有一个标题和一只脚

解决方案

绝对URL。 包括像你说的文件,并参考Javascript / CSS / etc。带绝对URL的文件。以下是您的标题可能如下所示:

 < html& 
< head>
< title> Foo Bar< / title>
< link rel =stylesheethref =/ path / to / stylesheet.css/>
< script src =/ path / to / script.js>< / script>
< / head>
< body>
...

注意所有的URL都以正斜杠开头。这意味着这些路径是绝对的,或相对于根。您可以将它包含在任何目录中的任何页面上,并且它们将始终正确加载。


I am suffering a serious problem: after a long time I decided I am not able to solve this horrible problem and shall look for help somewhere. Here is what I want to ask.

Lets say I am running a webiste: xyx.com ( apache , php , mysql ) All page same .php no html.

No I have folder structure like this / : root , /abc : another folder in root: both root and /abc has php page which include header and footer. Header and footer contains some url like home , services , about us etc.

So I had to copy same header and footer with its images folder in both root and /abc so that It works. Now I have problem whenever I have to change something I have to change in both place. Problem is not really two folders If I have to make more folder then I will be doomed to make small change I have to change every place. Now If I make one common header and footer and use include() , then I am facing problem Since header includes css , javascript and from the /abc folder path will be different lets say even if I manage this by php using if condition still it will not work cuz css has itself so many images as style. Now I can't change css since it will be a problem, I don't want two version of css which will somehoe affect loading time. I am already putting heavy load on website which gives me average load time of 6 seconds which is too slow. I hope i was able to convey you guys whoever read this post. If not then please post query I will reply you.

Thanks a trillion :)

Now my problem is I want to have one common header and footer

I have one header and one foot

解决方案

The answer is to use absolute URLs. include the files like you said, and refer to the Javascript/CSS/etc. files with absolute URLs. Here's what your header might look like:

<html>
    <head>
        <title>Foo Bar</title>
        <link rel="stylesheet" href="/path/to/stylesheet.css" />
        <script src="/path/to/script.js"></script>
    </head>
    <body>
        ...

Notice all of the URLs start with a forward slash. This means that those paths are absolute, or relative to the root. You can include it on any page in any directory, and they will always load properly.

这篇关于如何使常见的页眉和页脚..大问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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