php 如何将静态页面添加到 WordPress?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2363428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add static pages to WordPress?
提问by Sarfraz
How do I add my own static HTML pages to WordPress?
如何将我自己的静态 HTML 页面添加到 WordPress?
For example, let's say I have a page, products.html, how would I add it to WordPress (any menu, etc.) and once added, how do I visitthem, because WordPress had a typical URL structure?
例如,假设我有一个页面,products.html我如何将它添加到 WordPress(任何菜单等),一旦添加,我如何访问它们,因为 WordPress 有一个典型的 URL 结构?
采纳答案by Scott Cranfill
The static page functionality of WordPress is called, cleverly, "Pages." You can read all about them here: https://wordpress.org/support/article/pages/.
WordPress 的静态页面功能被巧妙地称为“页面”。您可以在此处阅读有关它们的所有信息:https: //wordpress.org/support/article/pages/。
回答by Kelly Conway
If you (as the OP asked) want it to appear without having to add .html, simply create a folder at the same location where your WP site's index.php appears, and then name the file that you put inside that folder index.html.
如果您(如 OP 要求)希望它出现而不必添加 .html,只需在您的 WP 站点的 index.php 出现的同一位置创建一个文件夹,然后命名您放入该文件夹中的文件 index.html .
Example, if you have a WordPress installation at doesnotexist.com and you want to add a static page, separate from your WP installation, that people can get to at doesnotexist.com/wedding - create the folder named wedding, and put the HTML in an index.html file inside the wedding folder. You also can then of course put other files in that folder or in folders within it so that the static page can reference images, styles, code, etc.
例如,如果您在 dosnotexist.com 上安装了 WordPress,并且您想添加一个与 WP 安装分开的静态页面,人们可以在 dosnotexist.com/wedding 上访问该页面 - 创建名为 Wedding 的文件夹,然后将 HTML 放入婚礼文件夹内的 index.html 文件。然后,您当然也可以将其他文件放在该文件夹或其中的文件夹中,以便静态页面可以引用图像、样式、代码等。
As someone said above, if the file for the URL exists, then WP won't get invoked to route the request. If you later remove the "wedding" folder or the "index.html" file from within it, anyone who tries to get to doesnotexist.com/wedding thenwould be routed to WP and, if no matching permalink was found, they'd see the 404 page not found error or whatever your theme or a plug-in is set up to show for broken links.
正如上面有人所说,如果 URL 的文件存在,则不会调用 WP 来路由请求。如果以后删除“婚礼”文件夹或从其中的“的index.html”文件,谁试图去doesnotexist.com/wedding然后将被路由到WP,如果没有匹配的永久链接被发现了,他们会查看 404 页面未找到错误或您的主题或插件设置为显示损坏的链接。
回答by markratledge
Do you mean Page Templates?: Page Templates ? WordPress Codex. You can make a new page template and modify the php and xhtml of it (and add static html), and then use that template when you generate a new Page in the wordpress editor.
你的意思是页面模板?:页面模板?WordPress 法典。您可以创建一个新的页面模板并修改其中的 php 和 xhtml(并添加静态 html),然后在 wordpress 编辑器中生成新页面时使用该模板。
If you simply add a static html file to your wordpress directory, it may or may not work, depending on mod rewrite.
如果您只是将一个静态 html 文件添加到您的 wordpress 目录中,它可能会或可能不会工作,具体取决于 mod 重写。
回答by Ali D.
Just upload it in your wordpress root (where you have index.php of WP), suppose if you put your products.html is put in a directory myproduct/, then it will be accessible via the url: http://www.yoursite.com/myproduct/products.html. Hope it answers your request.
只需将其上传到您的 wordpress 根目录(您有 WP 的 index.php 的位置),假设您将 products.html 放在目录 myproduct/ 中,则可以通过以下网址访问它: http://www.yoursite .com/myproduct/products.html。希望它能回答您的要求。
回答by Andromeda
You do not need to install any additional plug-in. Just follow the following procedure and you are good to go.
您不需要安装任何额外的插件。只需按照以下步骤操作即可。
- Create a page under Administration>Pages>Add new.
- Enter the nameyou want for your page, the custom URLand press publish.
- This would generate a record in your database under the wp_poststable. (wp_ is the default prefix for your wordpress tables. If you changed it during the installation procedure, replace it with your custom prefix). Find the IDthat has the name of your page in the table.
- Go to wp-content\themes\YOUR_ACTIVE_THEMEin your wordpress installation directory or in the sub-folders(it depends how the theme has been structured). There would be page.phpfile. Create a page-{ID}.phpfile in the same directory.
- It's ready. Add any static html file to page-{ID}.phpfile.
- 在Administration>Pages>Add new下创建一个页面。
- 输入您想要的页面名称、自定义URL,然后按发布。
- 这将在wp_posts表下的数据库中生成一条记录。(wp_ 是 wordpress 表的默认前缀。如果您在安装过程中更改了它,请将其替换为您的自定义前缀)。在表中找到具有您的页面名称的ID。
- 转到wordpress 安装目录或子文件夹中的wp-content\themes\YOUR_ACTIVE_THEME(这取决于主题的结构)。会有page.php文件。在同一目录中创建一个page-{ID}.php文件。
- 准备好了。将任何静态 html 文件添加到page-{ID}.php文件中。
Now, if you go the custom URL, you can find the static content you put in page-{ID}.phpfile.
现在,如果您转到自定义URL,您可以找到放置在page-{ID}.php文件中的静态内容。
回答by Lekter
You can also use a free WP plugin, just upload the archive with the plugin. It's very easy to add a static HTML to WordPress using the Static Pages https://designmodo.com/static-pages/
您也可以使用免费的 WP 插件,只需使用插件上传存档即可。使用静态页面https://designmodo.com/static-pages/将静态 HTML 添加到 WordPress 非常容易
You can customize your first page also.
您也可以自定义您的第一页。
回答by Kris C
To do what you describe, put the products.html page in your public_html directory. Edit your wordpress theme's header.php file to add to the menu section a link to the products.html page. You may have to use an absolute path in the URL depending on how you have things setup.
要执行您所描述的操作,请将 products.html 页面放在您的 public_html 目录中。编辑您的 wordpress 主题的 header.php 文件,将指向 products.html 页面的链接添加到菜单部分。您可能必须在 URL 中使用绝对路径,具体取决于您的设置方式。
If you want to retain the wordpress navigation on the products.html so you can browse back to the wordpress parts of your site, you'll need to replicate the header html within that page.
如果您想在 products.html 上保留 wordpress 导航以便您可以浏览回站点的 wordpress 部分,则需要在该页面中复制标题 html。
Based on this drawback and depending on your requirements I'd recommend considering using either pages or page templates as suggested in the other answers so that the products page is part of the wordpress layout and you can take advantage of a shared navigation / look and feel etc.
基于这个缺点并根据您的要求,我建议考虑使用其他答案中建议的页面或页面模板,以便产品页面成为 wordpress 布局的一部分,您可以利用共享导航/外观和感觉等等。
回答by muraguri2005
Add a page with format page-{slug}.php for example page-products.phpto your theme. You also need to add an empty page on wordpress under pages with that name i.e. if your for example your file is page-products.php, the id for the page you create on wordpress should be products. This should work. For more information, you can check this link https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-a-custom-page-template-for-one-specific-page.
添加一个格式为 page-{slug}.php 的页面,例如page-products.php到您的主题。您还需要在具有该名称的页面下在 wordpress 上添加一个空页面,例如,如果您的文件是page-products.php,那么您在 wordpress 上创建的页面的 id 应该是products。这应该有效。有关更多信息,您可以查看此链接https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-a-custom-page-template-for-one-specific-页。
回答by Krafter
You can use my plugin. Download from WP repository. After installation you will have HTML Pages option under Pages. It will output your custom HTML under custom URI of your choosing so you don't have to mess around with folders.
你可以使用我的插件。从 WP 存储库下载。安装后,您将在页面下有 HTML 页面选项。它将在您选择的自定义 URI 下输出您的自定义 HTML,因此您不必弄乱文件夹。
Update- exact steps to accomplish what you want:
更新- 完成您想要的确切步骤:
1) Install and activate a Wordpress plugin called WP Custom HTML Pages
1) 安装并激活一个名为 WP Custom HTML Pages 的 Wordpress 插件
2) Use the new submenu item (Pages->HTML Pages) to create a new HTML page
2)使用新的子菜单项(Pages->HTML Pages)创建一个新的HTML页面
3) In "Page Permalink" field enter the custom URI you wish to assign to your page, for example /my-html-page(at the time of writing this answer, it is required that the value you enter starts with "/" character) and in "HTML Page Code" field enter all the HTML and CSS of the page document that you wish to display
3) 在“页面永久链接”字段中输入您希望分配给您的页面的自定义 URI,例如/my-html-page(在撰写此答案时,您输入的值必须以“/”开头字符)并在“HTML 页面代码”字段中输入您希望显示的页面文档的所有 HTML 和 CSS
4) Click "Publish" then go to yourwebsite.com/my-html-page and you should see your static HTML page, providing its status is set to "published"
4) 单击“发布”,然后转到 yourwebsite.com/my-html-page,您应该会看到静态 HTML 页面,前提是其状态设置为“已发布”
回答by Beaniie
It may not be the best of solutions, but the way I got round this was adding multiple page templates. For example, I call one 'contact-page', then I create a contact page in the pages tab and apply that template. I then use the page template to display the static html.
这可能不是最好的解决方案,但我解决这个问题的方法是添加多个页面模板。例如,我调用一个“联系页面”,然后在页面选项卡中创建一个联系页面并应用该模板。然后我使用页面模板来显示静态 html。
Not a perfect but gets the job done. :)
不是完美的,但可以完成工作。:)

