嗨我正在尋找一種非常簡單的快速(無插件)方式在頁面模板中添加一個表單,該表單允許登錄用戶從WP-Admin外部發布信息。所以基本上這篇文章將在登錄的作者之下。WordPress公共郵局表格
我一直在網上尋找一些教程等左右,但還沒有太多的運氣和許多人似乎要選擇插件等,
誰能幫助表示感謝。
嗨我正在尋找一種非常簡單的快速(無插件)方式在頁面模板中添加一個表單,該表單允許登錄用戶從WP-Admin外部發布信息。所以基本上這篇文章將在登錄的作者之下。WordPress公共郵局表格
我一直在網上尋找一些教程等左右,但還沒有太多的運氣和許多人似乎要選擇插件等,
誰能幫助表示感謝。
您可以使用wp_insert_post()
函數。
看看這個。例如,您可以將其粘貼到category.php
中,然後訪問類別頁面並進行檢查。但要確保將頂級代碼放在get_header()
函數之上。
<?php
if(isset($_POST['new_post']) == '1') {
$post_title = $_POST['post_title'];
$post_category = $_POST['cat'];
$post_content = $_POST['post_content'];
$new_post = array(
'ID' => '',
'post_author' => $user->ID,
'post_category' => array($post_category),
'post_content' => $post_content,
'post_title' => $post_title,
'post_status' => 'publish'
);
$post_id = wp_insert_post($new_post);
// This will redirect you to the newly created post
$post = get_post($post_id);
wp_redirect($post->guid);
}
?>
-
<!-- this form shows only if user is logged in -->
<?php if (is_user_logged_in()) { ?>
<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<?php wp_dropdown_categories('orderby=name&hide_empty=0&exclude=1&hierarchical=1'); ?>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
<?php } ?>
更多的信息,你應該看看這裏wp_insert_post with a form
好運
如果你不介意改變你的主題,你可能想嘗試P2:http://wordpress.org/extend/themes/p2 這裏還有一個視頻在這裏:http://p2theme.com/
P2允許用戶直接從主頁發佈,這看起來就像您要找的東西。