您好,如何在我的 index.php 文件中创建自定义帖子,以便当有人安装模板时它会自动创建 5 个帖子?
我绑了这个:
<?php // Create post object
$my_post = array(
'post_title' => 'My post1',
'post_content' => 'This is my post8.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post ); ?>
但它没有用。我想做的是在<div>
标签内创建自定义帖子。因此,当用户安装主题时,他们已经使用主题创建,并且帖子将单独显示。例如:
<div class="demo">
<?php // Create post object
$my_post = array(
'post_title' => 'My post1',
'post_content' => 'This is my post8.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post ); ?>
</div>
<div class="description">
<span class="big"><?php // Create post object
$my_post = array(
'post_title' => 'My post2',
'post_content' => 'This is my post7.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post ); ?> </span>
</div>