嗨,我正在寻找一个非常简单,快速(没有插件,虽然)的方式来添加一个表单内的页面模板,将允许一个登录的用户从外部的可湿性粉剂管理发布。因此,基本上帖子将在登录的作者名下。
我一直在网上寻找一些教程等,但没有太多的运气,许多人似乎想选择插件等。
有人能帮上忙吗谢谢。
发布于 2011-01-28 09:53:58
您可以使用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
祝好运
发布于 2011-01-29 02:59:37
如果你不介意改变你的主题,你可能想试试P2:http://wordpress.org/extend/themes/p2在这里也有一段视频:http://p2theme.com/
P2允许人们直接从主页发帖,这似乎就是你想要的。
https://stackoverflow.com/questions/4823847
复制相似问题