函数创建一个页面,如果要将模板链接到该页面
if (! function_exists(\'create_page\')) {
function create_page($title, $template = 0){
$a = get_page_by_title( $title, \'post\' );
if ($a == null || $a->post_status == \'trash\') {
$page = array(
\'post_type\' => \'page\',
\'post_title\' => $title,
\'post_status\' => \'publish\'
);
$post_id = wp_insert_post( $page );
update_post_meta($post_id, \'_wp_page_template\', $template);
echo \'<a style="color:green;">page \'.$title.\' created.</a><br>\';
} else {
echo \'page \'.$title.\' already exists!<br>\';
}
}
}
那么可以这样称呼
create_page(\'my_custom_page\');
如果页面有模板,我们可以调用如下函数:
create_page(\'my_custom_page\',\'folder/mycustom_template\');