2016-07-07 97 views
1

我是開發wordpress插件的新手。我正在開發一個插件,並且我已經成功創建了一個新頁面,只要插件被激活,但我想添加一個自定義的PHP模板文件到該頁面。這意味着激活我想用自定義模板創建一個自定義頁面。有可能嗎?使用自定義插件wordpress將頁面模板添加到自定義頁面

要創建一個新的頁面我已經使用這個代碼,但在其上添加模板的東西找不到任何東西:

register_activation_hook(__FILE__,'my_plugin_install'); 
function my_plugin_install() { 
    global $wpdb; 
    $the_page_title = 'Custom Cart'; 
    $the_page_name = 'cart'; 
    delete_option("Custom Cart"); 
    add_option("Custom Cart", $the_page_title, '', 'yes'); 
    delete_option("cart"); 
    add_option("cart", $the_page_name, '', 'yes'); 
    delete_option("my_plugin_page_id"); 
    add_option("my_plugin_page_id", '0', '', 'yes'); 
    $the_page = get_page_by_title($the_page_title); 
    if (! $the_page) { 
     $_p = array(); 
     $_p['post_title'] = $the_page_title; 
     $_p['post_content'] = "This text may be overridden by the plugin. You shouldn't edit it."; 
     $_p['post_status'] = 'publish'; 
     $_p['post_type'] = 'page'; 
     $_p['comment_status'] = 'closed'; 
     $_p['ping_status'] = 'closed'; 
     $_p['post_category'] = array(1); 
     $the_page_id = wp_insert_post($_p); 
    } 
    else { 
     $the_page_id = $the_page->ID; 
     $the_page->post_status = 'publish'; 
     $the_page_id = wp_update_post($the_page); 
    } 
    delete_option('my_plugin_page_id'); 
    add_option('my_plugin_page_id', $the_page_id); 
} 

回答

相關問題