简体   繁体   English

如何在Wordpress中制作自定义页面

[英]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}.phppage-{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.

相关问题 如何制作WordPress自定义页面 - How to make Wordpress Custom page 如何制作动态wordpress页面(自定义控件/页面模板框) - How to make a dynamic wordpress page (custom control/page template box) 如何在WordPress中制作自定义模板作为受密码保护的页面? - How to make a custom template in WordPress work as a password protected page? 如何在Wordpress 3.0中制作自定义帖子类型的页面? - How to make a page for Custom Post Types in Wordpress 3.0? 在拥有 WordPress 站点时,如何使自定义 php web 页面在 ZFDE316856817FE53586DZ 环境之外可见? - While having WordPress site, how do I make a custom php web page viewable outside the WordPress environment? 如何为自定义字段创建可排序的管理面板列,以计算Wordpress中的页面印象数 - How to make a sortable admin panel column for a custom field counting the number of page impressions in Wordpress 如何制作Wordpress自定义帖子类型固定链接 - How to make Wordpress Custom Post Type Permalink 如何为wordpress制作自定义图像调整大小命令? - How to make custom image resize command for wordpress? 如何在WordPress中为假人创建自定义帖子? - How to make custom posts in WordPress for a dummy? 如何制作以移动为中心的自定义 WordPress 页脚 - How to make custom WordPress footer centered on mobile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM