有一些免费插件可以让您从前端提交帖子:
而报酬更高的是:
但它们都不能为您的需求提供定制编码的灵活性,而前端的帖子实际上是一个显示表单并对其进行处理的问题,因此按照您的用例,您的表单应该是这样的:
<!-- New game Post Form -->
<div id="postbox">
<form id="new_post" name="new_post" method="post" action="">
<!-- game name -->
<p><label for="title">Game name</label><br />
<input type="text" id="title" value="" tabindex="1" size="20" name="title" />
</p>
<!-- game platform assuming that the taxonomy is named platform -->
<p><label for="Platform">Platform:</label><br />
<p><?php wp_dropdown_categories( \'show_option_none=Platform&tab_index=4&taxonomy=platform\' ); ?></p>
<!-- game Category -->
<p><label for="Category">Category:</label><br />
<p><?php wp_dropdown_categories( \'show_option_none=Category&tab_index=4&taxonomy=category\' ); ?></p>
<!-- game post type assuming that the post types are named: review,tutorial,cheat_list-->
<p><label for="post_type">This is a:</label><br />
<p><select name="post_type" id="post_type">
<option value="review">Review</option>
<option value="tutorial">Tutorial</option>
<option value="cheat_list"> Cheat list</option>
</select></p>
<!-- game Content -->
<p><label for="description">Content</label><br />
<textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea>
</p>
<!-- game tags -->
<p><label for="post_tags">Tags:</label>
<input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="new_game_post" />
<?php wp_nonce_field( \'new-post\' ); ?>
</form>
</div>
您的表单处理将是:
if( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == "new_game_post") {
// Do some minor form validation to make sure there is content
if (isset ($_POST[\'title\'])) {
$title = $_POST[\'title\'];
} else {
echo \'Please enter a game title\';
}
if (isset ($_POST[\'description\'])) {
$description = $_POST[\'description\'];
} else {
echo \'Please enter the content\';
}
$tags = $_POST[\'post_tags\'];
// Add the content of the form to $post as an array
$new_post = array(
\'post_title\' => $title,
\'post_content\' => $description,
\'post_category\' => array($_POST[\'cat\']), // Usable for custom taxonomies too
\'tags_input\' => array($tags),
\'post_status\' => \'publish\', // Choose: publish, preview, future, draft, etc.
\'post_type\' => $_POST[\'post_type\'] // Use a custom post type if you want to
);
//save the new post
$pid = wp_insert_post($new_post);
//insert taxonomies
wp_set_post_terms($pid,array($_POST[\'Platform\']),\'platform\',true);
}
这并不完美,但这只是一个开始,你应该有这个想法。
希望这有帮助