- 资源介绍
- 更新记录
- 安装教程
WordPress如何添加文章投稿功能
很多WordPress博客上都有用户投稿的功能,这个功能用处还是比较大的,不仅适用于文章投稿,还适用于友链提交、网址提交等需要用到表单提交的地方。
就像本站网址导航页面的网址提交,也算是一种投稿功能,只不过是投稿给网址导航而不是文章。如下图:

要实现文章投稿功能其实也挺简单的,下面分享我自用的投稿功能代码:
1、首先在当前主题的目录下新建一个php文件,命名为submit.php。
2、将下面功能代码添加到 submit.php 文件中。
功能代码
<script>alert(“网站标题不能为空!”);</script>
<meta http-equiv=”refresh” content=”0;url=”>
<script>alert(“网站地址不能为空!”);</script>
<meta http-equiv=”refresh” content=”0;url=”>
<script>alert(“网站描述不能为空,且不得少于5个字!”);</script>
<meta http-equiv=”refresh” content=”0;url=”>
<script>alert(“网站icon图标不能为空!”);</script>
<meta http-equiv=”refresh” content=”0;url=”>
网站地址: \’.$url.\’
网站描述: \’.$description.\’
网站icon图标:\’.$icon;
$tougao = array(
\’post_title\’ => $title,
\’post_content\’ => $post_content,
\’post_status\’ => \’publish\’,
//\’post_type\’ => \’site\’ //tougao_type是要保存到的自定义文章类型
);
// 将文章插入数据库
$status = wp_insert_post( $tougao );
if ($status != 0) {
?>
<script>alert(“发布成功!”);</script>
<meta http-equiv=”refresh” content=”0;url=”>
<script>alert(“发布失败,请重新填写!”);</script>
<meta http-equiv=”refresh” content=”0;url=”>
3、将下面表单代码添加到功能代码下面
添加表单
<form method=”post” action=””>
<input type=”text” id=”tougao_title” value=”” name=”tougao_title” placeholder=”网站标题”/>
<input type=”text” id=”tougao_url” value=”” name=”tougao_url” placeholder=”网站地址” />
<input type=”text” id=”tougao_url” value=”” name=”tougao_url” placeholder=”网站类别(请填写贵站类别)”/>
<input type=”text” id=”tougao_description” name=”tougao_description” placeholder=”网站描述”>
<input type=”text” id=”tougao_icon” value=”” name=”tougao_icon” placeholder=”网站icon图标”/>
<div class=”t”>
<input type=”hidden” value=”send” name=”tougao_form” />
<button class=”button” type=”submit” value=”提交” >提交申请</button>
<button class=”button” type=”reset” value=”重填” >清空</button>
</div>
</form>
4、添加页面内容代码
<div>
</div>
5、添加底部代码
6、最后新建页面,页面属性选择刚才创建的网址提交即可。
猜你喜欢
-
SEO优化要重视的要点
2021-04-24 -
WordPress 多媒体库添加分类和标签支持
2021-04-26 -
WordPress 根据时间自动切换主题配图和颜色
2021-04-26 -
WordPress工单插件AIO Support Center中文版
2021-04-24 -
WordPress技巧之如何禁止后台加载谷歌字体
2021-04-25 -
WordPress主题开发常用模板名称和头部函数大全
2021-04-26 -
delete_option()函数
2021-04-26 -
WordPress不用插件实现文章AJAX点赞、文章点赞排行
2021-04-25 -
WordPress 调用第三方头像
2021-04-26 -
register_nav_menus()函数
2021-04-26
-
网站首页优化注意要点
2021-04-24 -
加固WordPress让网站运营更安全
2021-04-26 -
RIPRO主题美化-开通VIP介绍页面升级VIP引导页
2021-04-24 -
WordPress文章随机显示缩略图的实现方法
2021-04-25 -
WordPress制作前端会员用户中心实用功能代码
2021-04-26 -
get_template_part()函数
2021-04-26 -
RiPro网盘链接检测插件V3.1重磅升级,支持百度网盘、蓝奏云、天翼云盘、坚果云盘
2021-04-24 -
大前端DUX6.0主题下载
2021-04-21 -
Lemars – 专业新闻博客资讯网站WordPress模板
2021-04-21 -
Ripro子主题-ziyuan-zhankr资源网类
2021-04-24
猜你在找
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 大资源
- 2021-04-25Hi,初次和大家见面了,请多关照!
最后编辑:2021-04-25

