PHP包含外部文档的页脚链接

时间:2020-12-27 09:51:01

I am currently building a few one-page websites that use the same footer links. As I would like to be able to update them all at the same time, I was wondering if PHP could be used to achieve this. I was thinking that I could write the links in HTML in an external document and use the include function to grab the html and output it in each of the footers. I am new to php, so I am sorry if this is a very basic question. Any help is greatly appreciated.

我目前正在构建一些使用相同页脚链接的单页网站。由于我希望能够同时更新它们,我想知道是否可以使用PHP来实现这一目标。我想我可以在外部文档中用HTML编写链接,并使用include函数来获取html并将其输出到每个页脚中。我是php的新手,所以如果这是一个非常基本的问题,我很抱歉。任何帮助是极大的赞赏。

3 个解决方案

#1


0  

The best way is to create a folder named includes which is normal convention in php projects then create a page called footer.php and then include that file in your main file, for example you have file on root folder called index.php and you would like to include footer.php there you just write <?php include("foldername/filename.php");?> that in this case will be <?php include("includes/footer.php"); ?> . As you are new, for further reading you may have a look here.

最好的方法是创建一个名为includes的文件夹,这是php项目中的常规约定,然后创建一个名为footer.php的页面,然后在主文件中包含该文件,例如你在根文件夹中有一个名为index.php的文件,你会喜欢在footer.php中包含你只需写 在这种情况下将 。当你是新手时,为了进一步阅读,你可以看看这里。

#2


1  

If you're building separate websites and intend to use the same footer for all of them, you could create a sample footer html file and use PHP file_get_contents to display it on every website

如果您正在构建单独的网站并打算为所有网站使用相同的页脚,您可以创建一个示例页脚html文件并使用PHP file_get_contents在每个网站上显示它

#3


0  

In fact, the templates of many PHP applications like wordpress, works as you assume. They use include/require command.

实际上,像wordpress这样的许多PHP应用程序的模板都可以正常运行。他们使用include / require命令。

In the web root directory, files may organised like this:

在Web根目录中,文件可能组织如下:

Web Root
├── css
├── footer.php
├── header.php
├── images
├── index.php
├── js
└── list.php

In index.php and list.php, use include "header.php" and include "footer.php" to add header and footer codes. So, now if you change something in footer.php, when you visiting index.php and list.php, you can see the changes.

在index.php和list.php中,使用include“header.php”并包含“footer.php”来添加页眉和页脚代码。所以,现在如果你在footer.php中改变一些东西,当你访问index.php和list.php时,你可以看到这些变化。

PS: When should I use require_once vs include?

PS:我什么时候应该使用require_once vs include?

#1


0  

The best way is to create a folder named includes which is normal convention in php projects then create a page called footer.php and then include that file in your main file, for example you have file on root folder called index.php and you would like to include footer.php there you just write <?php include("foldername/filename.php");?> that in this case will be <?php include("includes/footer.php"); ?> . As you are new, for further reading you may have a look here.

最好的方法是创建一个名为includes的文件夹,这是php项目中的常规约定,然后创建一个名为footer.php的页面,然后在主文件中包含该文件,例如你在根文件夹中有一个名为index.php的文件,你会喜欢在footer.php中包含你只需写 在这种情况下将 。当你是新手时,为了进一步阅读,你可以看看这里。

#2


1  

If you're building separate websites and intend to use the same footer for all of them, you could create a sample footer html file and use PHP file_get_contents to display it on every website

如果您正在构建单独的网站并打算为所有网站使用相同的页脚,您可以创建一个示例页脚html文件并使用PHP file_get_contents在每个网站上显示它

#3


0  

In fact, the templates of many PHP applications like wordpress, works as you assume. They use include/require command.

实际上,像wordpress这样的许多PHP应用程序的模板都可以正常运行。他们使用include / require命令。

In the web root directory, files may organised like this:

在Web根目录中,文件可能组织如下:

Web Root
├── css
├── footer.php
├── header.php
├── images
├── index.php
├── js
└── list.php

In index.php and list.php, use include "header.php" and include "footer.php" to add header and footer codes. So, now if you change something in footer.php, when you visiting index.php and list.php, you can see the changes.

在index.php和list.php中,使用include“header.php”并包含“footer.php”来添加页眉和页脚代码。所以,现在如果你在footer.php中改变一些东西,当你访问index.php和list.php时,你可以看到这些变化。

PS: When should I use require_once vs include?

PS:我什么时候应该使用require_once vs include?