[英]How to make a custom page in Wordpress
Hi I'd like to create a totally custom page in wordpress where I'd add a lot of php code so I would prefer not to create it as a wordpress 'Page', but as a file 'filename.php' in my theme directory. 嗨,我想在wordpress中创建一个完全自定义的页面,在其中添加很多php代码,因此我宁愿不要将其创建为wordpress“页面”,而是创建为主题中的文件“ filename.php”目录。 Of course in that page I need to include wp functions and stuff and I plan to do it with require_once("../../../../wp-load.php");
当然,在该页面中,我需要包括wp函数和东西,并且我打算使用require_once("../../../../wp-load.php");
. 。
My problem is, how do I set the header info for a custom page like that (title, meta description etc..) and how do I add a rewrite rule to make it reachable like "website.dom/pagename". 我的问题是,如何为这样的自定义页面设置标题信息(标题,元描述等),以及如何添加重写规则以使其可访问,例如“ website.dom / pagename”。 Thanks in advance for any answer, and even if you tell me that the best way is to use wordpress default "Add New Page", I'd prefer not to use any script to insert php code in the page, thanks. 在此先感谢您提供任何答案,即使您告诉我最好的方法是使用WordPress默认的“添加新页面”,我也不希望使用任何脚本在页面中插入php代码,谢谢。
I suggest you create a WP page, and set it to use a custom template. 我建议您创建一个WP页面,并将其设置为使用自定义模板。 Then, add your custom scripts to the template. 然后,将自定义脚本添加到模板。
WordPress has built in functionality to look for custom pages, and does so every time you open up a page. WordPress具有内置功能来查找自定义页面,并且每次打开页面时都会这样做。 To have WordPress find it you could for instance name the file page-{id}.php
or page-{slug}.php
and place it in your theme folder. 要让WordPress找到它,您可以例如将文件命名为page-{id}.php
或page-{slug}.php
并将其放置在主题文件夹中。 So if the name of your page i "about" - which you create as you usually would, using the admin section in WordPress - you name your file "page-about.php". 因此,如果您的页面名称是“ about”(通常使用WordPress中的admin部分创建的页面名称),则将文件命名为“ page-about.php”。 WordPress will then automatically load it. WordPress然后将自动加载它。
To load the title of your page, use get_header( 'about' );
要加载页面标题,请使用get_header( 'about' );
(Although, that's part of the header). (尽管这是标题的一部分)。
A good way to start would be to locate page.php
, holding the default template, copy it and rename it as explained above. 一个很好的开始方法是找到page.php
,保留默认模板,将其复制并重命名,如上所述。 Then edit it in any way you want. 然后以您想要的任何方式对其进行编辑。 You'll find a good guide here . 您将在这里找到一个很好的指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.