dougu4704
2015-10-05 21:35
浏览 85
已采纳

如何在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. 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");.

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". 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.

图片转代码服务由CSDN问答提供 功能建议

您好我想在wordpress中创建一个完全自定义的页面,我会添加很多php代码所以 我不想将其创建为wordpress'Page',而是将其作为文件'filename.php'创建在我的主题目录中。 当然在那个页面中我需要包含wp函数和东西,我计划用 require_once(“../../../../ wp-load.php”); 来做 。

我的问题是,如何设置自定义页面的标题信息(标题,元描述等...)以及如何添加重写规则以使其可访问 比如“website.dom / pagename”。 提前感谢您的回答,即使您告诉我最好的方法是使用wordpress默认“添加新页面”,我也不想使用任何脚本在页面中插入php代码,谢谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • donoworuq450547191 2015-10-05 21:42
    已采纳

    WordPress has built in functionality to look for custom pages, and does so every time you open up a page. 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. 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". WordPress will then automatically load it.

    To load the title of your page, use 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. Then edit it in any way you want. You'll find a good guide here.

    打赏 评论
  • dqeonr8554 2015-10-05 21:40

    I suggest you create a WP page, and set it to use a custom template. Then, add your custom scripts to the template.

    打赏 评论

相关推荐 更多相似问题