[英]Wordpress about me page, replicate when installing new theme
我要做的是安装一个模板,该模板会自动创建一个页面,就像第一次安装wordpress时创建的abotu me页面一样。 我怎样才能做到这一点? 安装新主题时如何运行SQL语句? 因为页面存储在数据库中,所以我可以在安装主题时以这种方式上载页面,但是我没有任何想法。
最好的祝福
JCHASE,我同意wp_insert_post部分,我建议的唯一一件事是使用动作挂钩而不是$ _GET。 使用add_action('after_setup_theme','my_initiation_function')是一个更好的选择
这是发布帖子的方法:
global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
请参阅下面的页面。 请参阅此页面作为参考。
我上面的答案是添加帖子。 下面的答案是添加一个页面(它添加有关主题激活的页面):
if (isset($_GET['activated']) && is_admin()){
$new_page_title = 'This is the page title';
$new_page_content = 'This is the page content';
$new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
//don't change the code bellow, unless you know what you're doing
$page_check = get_page_by_title($new_page_title);
$new_page = array(
'post_type' => 'page',
'post_title' => $new_page_title,
'post_content' => $new_page_content,
'post_status' => 'publish',
'post_author' => 1,
);
if(!isset($page_check->ID)){
$new_page_id = wp_insert_post($new_page);
if(!empty($new_page_template)){
update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.