1、在当前使用的主题根目录下建一个模板:
代码:
-
-
-
-
- if( 'POST' == $_SERVER['REQUEST_METHOD'] && !emptyempty( $_POST['action'] ) && $_POST['action'] == 'post' ) {
- if (!is_user_logged_in() ) auth_redirect();
- if(!current_user_can( 'publish_posts' ) ) {
- wp_redirect( get_bloginfo( 'url' ) . '/' );
- exit;
- }
- check_admin_referer( 'new-post' );
- $user_id = $current_user->user_id;
-
- if (isset ($_POST['title'])) {
- $title = $_POST['title'];
- } else {
- echo '请输入文章标题!';
- }
- if (isset ($_POST['content'])) {
- $content = $_POST['content'];
- } else {
- echo '请输入文章内容!';
- }
- $tags = $_POST['post_tags'];
- $post = array(
- 'post_author' => $user_id,
- 'post_title' => $title,
- 'post_content' => $content,
- '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');
- ?>
-
-
"width:100%; text-align: center;">
-
-
二、新建一个页面,模板选择刚才新建的“Front Post”;
三、通过
域名>/?page_id=<刚才新建的页面ID>
即可访问发布文章页面。
原文来自站长网
阅读(2401) | 评论(0) | 转发(0) |