add page template by name
-
i am adding templates from a plugin and want to create a page from the plugin as well, which works but i have issues with the correct template being applied. According to the codex, wp_insert_post template=> templatename.php which is probably looking in the theme for a template file.
Is there anyway around this?
function create_pages() { $templates= array( //name=template 'Advert-Payment' => 'ad-payment-screen' ); foreach ($templates as $name=>$template) { if(get_option($name)===False) { $post= array( 'post_title' => $name, 'post_name' =>$name, 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '', 'post_author' => 1, 'page_template' => $template ); $postid=wp_insert_post( $post ); add_option( $name, $name ); } } } add_action('wp_loaded', 'create_pages');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘add page template by name’ is closed to new replies.