简体   繁体   English

Wordpress子主题,创建自定义php模板页面

[英]Wordpress child theme, creating a custom php template page

I am currently working on a project that uses a child theme (storefront is the parent theme). 我目前正在使用子主题(店面是父主题)的项目中工作。 I need to be able to code using pure php / javascript (outside wordpress admin). 我需要能够使用纯php / javascript(wordpress管理员之外)进行编码。 Other custom template pages have *-content.php structure, such as: foo-content.php . 其他自定义模板页面具有*-content.php结构,例如: foo-content.php

I created the custom page I'd like to develop on. 我创建了想要开发的自定义页面。 However, when visiting the url, I am getting a blank white page. 但是,当访问URL时,我得到的是空白页面。 I am having a hard time understanding why this is. 我很难理解为什么会这样。

Additionally, I tried going to wordpress admin and creating the page in the admin so it matches the file name I created my.domain.com/foo , nothing seems to work - I keep getting a blank white page and no errors. 另外,我尝试进入wordpress admin并在admin中创建页面,以使其与我创建的文件名my.domain.com/foo ,但似乎无济于事-我一直得到空白页且没有错误。 Any ideas why this is? 任何想法为什么会这样?

I appreciate any suggestions. 我感谢任何建议。

If you specifically need to make a page template, read through the Page Template Files section of the Theme Developers Handbook. 如果您特别需要制作页面模板,请通读主题开发人员手册的“ 页面模板文件”部分。

The key takeaways would be that you need a Page Template Header in the file, which at a minimum would include a Template Name like so: 关键要点是,您需要在文件中包含一个页面模板标题,该页面模板标题至少应包含一个模板名称,如下所示:

<?php
/*
    Template Name: Foo Content
*/
// Your code here

As well as you would then go into your wp-admin and make a new page, and select your Foo Content page template in the template selector on the right hand side. 就像您随后进入wp-admin并新建一个页面一样,然后在右侧的模板选择器中选择Foo Content页面模板。

You may also look at the Template Hierarchy if it's not specificaly "Page Templates" that you need. 如果不是您需要的“页面模板”,您也可以查看模板层次结构

Have you included an index.php file? 您是否包含index.php文件? Without it your website won't have a starting point, you won't see any errors but just a blank page. 没有它,您的网站将没有起点,您只会看到空白页面,不会看到任何错误。 I would ensure you have an index.php in there. 我会确保您那里有一个index.php。 It should contain: 它应包含:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

If you create a new WP template (as a php file), you afterwards have to create a page in the Wordpress backend and choose that template file as the template for you newly created WP page. 如果您创建新的WP模板(作为php文件),则之后必须在Wordpress后端中创建一个页面,然后选择该模板文件作为您新创建的WP页面的模板。 Then the url for that page will be the slug of that WP page. 然后,该页面的URL将是该WP页面的链接。 Open the file from within the WP editor after you save it, then you see its URL. 保存后,从WP编辑器中打开文件,然后看到其URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM