<!–以下为提交文章的动作–> <?php
if( ‘POST’ == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo ‘Please enter a title’;
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo ‘Please enter the content’;
}
$tags = $_POST['post_tags'];
$post = array(
‘post_title’ => $title,
‘post_content’ => $description,
‘post_category’ => array($_POST['cat']),
‘tags_input’ => $tags,
‘post_status’ => ‘publish’,
‘post_type’ => $_POST['post_type']
);
wp_insert_post($post);
wp_redirect( home_url() );
}
do_action(‘wp_insert_post’, ‘wp_insert_post’);
?>
<!–以下为发表文章的表单–> <script type=”text/javascript”>
function log_check(){
if(new_post.title.value==”"){
alert(“文章标题没输入哦!”);
new_post.title.focus();
return false;
}
if(new_post.post_tags.value==”"){
alert(“文章标签没设置啊! “);
new_post.post_tags.focus();
return false;
}
if(new_post.description.value==”"){
alert(“文章内容是空的啊? “);
new_post.description.focus();
return false;
}
}
</script> <form id=”new_post” name=”new_post” method=”post” action=” ” onsubmit=”return log_check();”>
<p><label for=”title”>文章标题:</label><input type=”text” id=”title” value=”输入文章标题” onfocus=”this.value==this.defaultValue?this.value=”:null;” onblur=”this.value==”?this.value=’输入文章标题’:null;” tabindex=”1〃 size=”80〃 name=”title” /></p>
<p><label for=”post_tags”>文章标签:</label><input type=”text” value=”输入文章TAGS,用单引号隔开” onfocus=”this.value==this.defaultValue?this.value=”:null;” onblur=”this.value==”?this.value=’输入文章TAGS,用单引号隔开’:null;” tabindex=”5〃 size=”80〃 name=”post_tags” id=”post_tags” /></p>
<p><label for=”cat”>文章分类:</label><?php wp_dropdown_categories( ‘show_option_none=选择文章分类&tab_index=4&taxonomy=category’ ); ?></p>
<p><label for=”description”>文章内容:</label>
<?php wp_editor( ”, description, $settings = array(
‘quicktags’=>1,
‘tinymce’=>0,
‘media_buttons’=>0,
‘textarea_rows’=>4,
‘editor_class’=>”textareastyle”
) ); ?></p>
<p>
<input type=”submit” value=”发 布” tabindex=”6〃 id=”submit” name=”submit” class=”inputy”/>
<input type=”reset” value=”重 置” id=”reset” name=”" class=”inputn”/>
</p>
<input type=”hidden” name=”post_type” id=”post_type” value=”post” />
<input type=”hidden” name=”action” value=”post” />
<?php wp_nonce_field( ‘new-post’ ); ?>
</form>
WordPress默认编辑器tinymce调用 <?php wp_editor( $content, $editor_id, $settings = array() ); ?>//默认调用格式 <?php wp_editor( ”, description, $settings = array(
‘quicktags’=>1,//启用快捷键
‘quicktags’=> array(‘buttons’ => ‘strong,em,link,del,img,ul,ol,li,code,spell,close’,),
//WP默认按钮有strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close 请自行选择
‘tinymce’=>0,//可视化编辑停用
‘media_buttons’=>0,//媒体库上传按钮停用
‘textarea_rows’=>4,
‘editor_class’=>”textareastyle”//编辑器外框样式
) ); ?>
在调用默认编辑器时需要你的主题中有如下两个调用,如果没有将不能调用相关的JS和CSS了:
<?php wp_head(); ?>
<?php wp_footer(); ?>