WordPress自动创建帖子 [英] Wordpress auto create posts
本文介绍了WordPress自动创建帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,如何在index.php文件中创建自定义帖子,以便当有人安装模板时它会自动创建5个帖子?
Hello how do I create custom posts inside my index.php file so when someone installs the template it automatically creates like 5 posts?
我绑了这个:
<?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>
标记内创建自定义帖子.因此,当用户安装主题时,他们将已经与主题一起创建,并且帖子将单独显示.
例如:
But it didn't work. What I am trying to do is create custom posts inside <div>
tags. So when the users installs the theme they will already be created with the theme and the post will display individually.
For example:
<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>
推荐答案
好像您正在使用 wp_insert_post().
- 确保您实际上具有ID为
8
和39
的类别. - 使用类似
$var = wp_insert_post($your_args)
的名称.然后回显$var
以获得创建的帖子的ID.
- Make sure you actually have the categories with IDs
8
and39
. - use something like
$var = wp_insert_post($your_args)
. Then echo$var
to get the ID of the post that was created.
这篇关于WordPress自动创建帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文