如何通过一个应用程序在网页上放置横幅到网站的所有页面

发布于 2024-07-10 04:56:16 字数 31 浏览 5 评论 0原文

如何通过一个应用程序在网站的所有页面上放置横幅?

How can I place a banner on webpage with one application to all pages of a website?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

青春如此纠结 2024-07-17 04:56:16

一种方法是将横幅放入文件中,然后将其包含在每个其他页面上。 这样,您只需更改一个位置的代码即可在整个站点范围内更新横幅。

因此,PHP 示例如下:

banner.inc.php:
<?php
  // echo out banner here...
?>

然后,在您的其他页面上:

include("banner.inc.php");

One way of doing this is to put your banner into a file, then include that one on each of your other pages. This way, you only have to change the code in one place to update the banner site-wide.

So, a PHP example would be:

banner.inc.php:
<?php
  // echo out banner here...
?>

Then, on your other pages:

include("banner.inc.php");
梦初启 2024-07-17 04:56:16

您只需创建一个包含在所有页面中的标头文件,并在其中包含横幅代码。 所有语言的解决方案几乎都是相同的。 如果您的主机允许服务器端包含,您甚至可以使用(几乎)纯 HTML 执行完全相同的操作。 您也可以使用 JavaScript 轻松完成此操作。

You can just create a header file that you include in all your pages, and include the banner code in it. The solution is pretty much the same in all languages. If your host allows server-side includes, you can even do exact same thing with (nearly) pure HTML. You can also do it with JavaScript pretty easily.

留一抹残留的笑 2024-07-17 04:56:16

您的所有页面都有一个全局模板吗? 定义所有页面的基本结构,同时将特定内容填充到正文的某些部分? 如果您有类似的内容,您可以修改全局模板以具有您想要的横幅,并且它将显示在您的所有页面上。

谷歌“html 模板”了解更多信息。

Do you have a global template for all your pages? Something where the basic structure of all your pages is defined while the specific stuff is filled into parts of the body? If you had something like this you could modify the global template to have the banner you want and it would show on all your pages.

Google "html templating" for more.

执笏见 2024-07-17 04:56:16

我建议使用母版页。 这样,如果您需要在整个项目中进行全局更改,您只需在一个地方进行更改。 而且它们使用起来非常简单。

I recommend using master pages. That way if you have something that has to be changed globally across the project you only have to change it in one place. And they are really simple to use.

别念他 2024-07-17 04:56:16

如果您的 Web 服务器是 IIS,并且您了解一点 CSS,则无需使用 Perl 即可完成此操作,无需触及任何其他文件,但会牺牲一些性能。

IIS 允许您将 HTML 片段插入到所提供的任何内容中:
http: //www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e27f918e-89a9-45a8-8604-2ad2ded09d64.mspx?mfr=true

如果所述页脚文件,则具有将其推到顶部的CSS ,那么你就会得到你正在寻找的行为。

请注意,这不是一个理想的解决方案,但它是一个快速而肮脏的补丁,直到您可以返回并使用母版页或其他内容改造所有页面相似的。

If your web server is IIS, and you know a smidge of CSS you can do this without perl, without touching any other files, but at the cost of some performance.

IIS allows you to insert an HTML snippet into anything served:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e27f918e-89a9-45a8-8604-2ad2ded09d64.mspx?mfr=true

If said footer file, had CSS which shoved it to the top, then you would get the behavior you are looking for.

Please note, that this is NOT an ideal solution, but it is a quick and dirty patch until you can go back and retrofit all of your pages with a master page or something similar.

清眉祭 2024-07-17 04:56:16

如果它真的应该出现在您网站的每个页面上,我认为它是网站设计的一部分,而不是内容本身。 在这种情况下,您很容易有理由设置 background-image在你的CSS中。 当然,您可能仍然需要在 html 中包含某种占位符元素,但至少您可以一起更新整个网站。

If it really should be on every page of your site, I'd argue that it's part of the site design rather than the content itself. In this case, you are easily justified in setting a background-image in your css. Of course, you probably then still have to have some sort of place-holder element in your html, but at least you could update the whole site together.

一直在等你来 2024-07-17 04:56:16

好吧,希望您设计的网站这样,如果您需要全局更改某些内容,您只需编辑页眉或页脚文件即可。

如果没有,我会使用 Perl 浏览所有文件,并进行搜索和替换。

Well, hopefully you would have designed the website so that if you need to change something globally, you can just edit a header or footer file.

If not, I would use Perl to go through all the files, and do a search and replace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文