我想做的是安装一个模板,这个模板会自动创建一个页面,就像你第一次安装wordpress时创建的abotu me页面一样。我该怎么做呢?如何在安装新主题时运行SQL语句?由于页面存储在数据库中,我可以在安装主题时以这种方式上传页面,但我不知道如何上传。
诚挚的问候
发布于 2012-01-08 03:21:59
我上面的回答是为了添加帖子。下面的答案是添加一个页面(添加关于主题激活的页面):
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);
}
}
}发布于 2012-01-08 15:20:24
$_GET,我同意JCHASE的观点,我唯一建议的就是使用操作钩子而不是JCHASE。使用add_action( 'after_setup_theme','my_initiation_function')会是一个更好的选择
发布于 2012-01-08 03:17:35
这是如何在文章中做到这一点:
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);请看下面的页面。有关参考信息,请参见this page。
https://stackoverflow.com/questions/8772296
复制相似问题