Php wordpress-在子文件夹中使用模板动态创建页面

Php wordpress-在子文件夹中使用模板动态创建页面,php,wordpress,Php,Wordpress,我使用下面的代码在主题激活时创建页面。当页面模板位于主题的根目录中时,这一切都非常有效。但是,我试图从“页面模板”目录根->页面模板中引用我的模板文件。我做错了什么 if (isset($_GET['activated']) && is_admin()){ add_action('init', 'create_initial_pages'); } function create_initial_pages() { $pages = array( //

我使用下面的代码在主题激活时创建页面。当页面模板位于主题的根目录中时,这一切都非常有效。但是,我试图从“页面模板”目录根->页面模板中引用我的模板文件。我做错了什么

if (isset($_GET['activated']) && is_admin()){
    add_action('init', 'create_initial_pages');
}

function create_initial_pages() {    
$pages = array(
     // Page Title and URL (a blank space will end up becomeing a dash "-")
    'Services' => array(
        // Page Content     // Template to use (if left blank the default template will be used)
        'Services Content'=>'page-bottom-sidebar.php'),
);

foreach($pages as $page_url_title => $page_meta) {
        $id = get_page_by_title($page_url_title);

    foreach ($page_meta as $page_content=>$page_template){
    $page = array(
        'post_type'   => 'page',
        'post_title'  => $page_url_title,
        'post_name'   => $page_url_title,
        'post_status' => 'publish',
        'post_content' => $page_content,
        'post_parent' => ''
    );

    if(!isset($id->ID)){
        $new_page_id = wp_insert_post($page);
        if(!empty($page_template)){
                update_post_meta($new_page_id, '_wp_page_template', $page_template);
        }
    }
 }
};
}

非常感谢您的帮助。我知道这很简单,我就是看不见。

当您的页面模板位于子目录中时,在设置“wp\u page\u”模板时,应将子目录与模板名称一起包括在内

因此,如果page-bottom-sidebar.php位于主题的页面模板目录中,而不是:

'Services Content'=>'page-bottom-sidebar.php'
您需要:

'Services Content'=>'page-templates/page-bottom-sidebar.php'