网站模板和源码
When each page of your website follows the same design theme, it is easy to create a template for the site using HTML and PHP. The specific pages of the site hold only their content and not their design. This makes design changes easy because changes take place on all the pages of the website at once, and there is no need to individually update specific pages when the design changes.
当您网站的每个页面都遵循相同的设计主题时,使用HTML和PHP为网站创建模板很容易。 该网站的特定页面仅保留其内容,而不包含其设计。 这使设计更改变得容易,因为更改会同时在网站的所有页面上进行,并且在设计更改时无需单独更新特定页面。
创建网站模板 ( Creating a Site Template )
The first thing you need to do is create a file called header.php. This file holds all the page design elements that come before the content. Here is an example:
您需要做的第一件事是创建一个名为header.php的文件。 该文件包含内容之前的所有页面设计元素。 这是一个例子:
My Site
我的网站
My Site Title
My Site Title
My Site menu goes here........... Choice 1 | Choice 2 | Choice 3
My Site menu goes here........... Choice 1 | Choice 2 | Choice 3
Next, make a file called footer.php. This file contains all the site design information that goes beneath the content. Here is an example:
接下来,创建一个名为footer.php的文件。 该文件包含位于内容下方的所有网站设计信息。 这是一个例子:
Copyright 2008 My Site
Copyright 2008 My Site
Finally, create the content pages for your site. In this file you:
最后,为您的站点创建内容页面。 在此文件中,您:
Call the header file (header.php)
调用头文件 (header.php)
- Put in the page-specific content 放入页面特定的内容
- Call the footer file (footer.php) 调用页脚文件(footer.php)
Here is an example of how to do this:
这是如何执行此操作的示例:
Sub-Page Title
Here is the specific content of this page....
Here is the specific content of this page....
提示 ( Tips )
- Remember to save all your files with the .php extension. 请记住以.php扩展名保存所有文件。
- You can have more than a header and a footer. If needed, create other files to include in the middle and call them the same way. 您不仅可以有页眉和页脚。 如果需要,创建其他文件以包含在中间,并以相同的方式调用它们。
- Couple your templates with the use of a style sheet to change style within the page-exclusive content. 将模板与样式表结合使用,以更改页面专有内容内的样式。
翻译自: https://www.thoughtco.com/how-to-template-your-site-2694216
网站模板和源码