ASTRA wordpress主题-企业建站-域名注册-虚拟主机-PHP主机提供商-免备案主机-香港主机-香港云服务器

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 1866|回复: 0

最近从ITbobo那移植来的wordpress投稿功能,分享给大家!

[复制链接]
发表于 2013-10-8 13:36:28 | 显示全部楼层 |阅读模式

之前本站有发布过一款仿新版蛋花儿主题,这款wordpress主题得到很多朋友的喜欢,可收到很多朋友的反馈说是要增加wordpress投稿功能,当时忙于其他的事情,一直没顾及上这款wordpress主题的维护工作!

而最近经常收到一些投稿主题的邮件,也是因为本站没有一个wordpress投稿功能,所以一直用发邮件代替着,其实小编知道有很多的投稿插件,但是小编一直提倡远离插件,提升速度的口号!

于是小编前些天从好友ITbobo主题里移植了其wordpress投稿功能,感觉十分的强大,纯代码完成!效率高!也易于使用!



不多说哈,开始教程啦!
首先在wordpress主题的根目录新建一个tougao.php,将下面的代码插入。。。对是插入!
  1. <?php  
  2. /*
  3.     Template Name: 投稿页面
  4. */  
  5. if( isset($_POST['tougao_form']) && $_POST['tougao_form'] == 'send'){  
  6.     if( isset($_COOKIE["tougao"]) && ( time() - $_COOKIE["tougao"] ) < 120 ){  
  7.         wp_die('您投稿也太勤快了吧,先歇会儿!');  
  8.     }  
  9.     //表单变量初始化  
  10.     $name = isset( $_POST['tougao_authorname'] ) ? $_POST['tougao_authorname'] : '';  
  11.     $email = isset( $_POST['tougao_authoremail'] ) ? $_POST['tougao_authoremail'] : '';  
  12.     $blog = isset( $_POST['tougao_authorblog'] ) ? $_POST['tougao_authorblog'] : '';  
  13.     $title = isset( $_POST['tougao_title'] ) ? $_POST['tougao_title'] : '';  
  14.     $tags = isset( $_POST['tougao_tags'] ) ? $_POST['tougao_tags'] : '';  
  15.     $category = isset( $_POST['cat'] ) ? (int)$_POST['cat'] : 0;  
  16.     $content = isset( $_POST['tougao_content'] ) ? $_POST['tougao_content'] : '';  
  17.     //表单项数据验证  
  18.     if ( emptyempty($name) || strlen($name) > 20 ){  
  19.         wp_die('昵称必须填写,且不得超过20个长度');  
  20.     }  
  21.     if ( emptyempty($email) || strlen($email) > 60 || !preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)){  
  22.         wp_die('邮箱必须填写,且不得超过60个长度,必须符合 Email 格式');  
  23.     }  
  24.     if ( emptyempty($title) || strlen($title) > 100 ){  
  25.         wp_die('文章标题必须填写,且不得超过100个长度');  
  26.     }  
  27.     if ( emptyempty($content) || strlen($content) < 100){  
  28.         wp_die('内容必须填写,且不得少于100个长度');  
  29.     }  
  30.     $tougao = array('post_title' => $title,'post_content' => $content,'post_status' => 'pending','tags_input' => $tags,'post_category' => array($category));  

  31.     $status = wp_insert_post( $tougao );//将文章插入数据库  
  32.     if ($status != 0){  
  33.         global $wpdb;  
  34.         $myposts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'pending' AND post_type = 'post' ORDER BY post_date DESC");  
  35.         add_post_meta($myposts[0]->ID, 'tcp_postauthor', $name);    //插入投稿人昵称的自定义域  
  36.         if( !emptyempty($blog))  
  37.             add_post_meta($myposts[0]->ID, 'tcp_posturl', $blog);    //插入投稿人网址的自定义域  
  38.         setcookie("tougao", time(), time()+180);  
  39.         wp_die('投稿成功!','投稿成功!');  
  40.     }else{  
  41.         wp_die('投稿失败!','投稿失败!');  
  42.     }  
  43. }  
  44. get_header();  
  45. ?>  
  46. <body>  
  47.     <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>   
  48.     <div id="wrapper" class="clearfix">  
  49.         <div class="tougao divmargin">  
  50.             <div class="entryy" style="background-color: #FFF8D9;border: 1px solid #FEBE8F;border-radius: 2px;color: #FF6600;padding:5px;margin:10px 10px 0px 10px;font-size:13px;">  
  51.                 <?php the_content('More &#187;'); ?>  
  52.             </div>  
  53.             <div class="entryy">  
  54.                 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">  
  55.                     <div id="basicinfo">  
  56.                         <p>  
  57.                             <label>作者昵称:</label>  
  58.                             <input type="text" value="" name="tougao_authorname" />  
  59.                             <small>*</small>  
  60.                         </p>  
  61.                         <p>  
  62.                             <label>E-Mail:</label>  
  63.                             <input type="text" value="" name="tougao_authoremail" />  
  64.                             <small>*</small>  
  65.                         </p>  
  66.                         <p>  
  67.                             <label>您的网站:</label>  
  68.                             <input type="text" value="" name="tougao_authorblog" />  
  69.                         </p>  
  70.                         <p>  
  71.                             <label>文章标题:</label>  
  72.                             <input type="text" value="" name="tougao_title" />  
  73.                             <small>*</small>  
  74.                         </p>  
  75.                         <p>  
  76.                             <label>文章分类:</label>  
  77.                             <?php wp_dropdown_categories('show_count=1&hierarchical=1'); ?>  
  78.                             <small>*</small>  
  79.                         </p>  
  80.                         <p>  
  81.                             <label>关键词:</label>  
  82.                             <input type="text" value="" name="tougao_tags" />  
  83.                             <small>*</small>  
  84.                         </p>  
  85.                     </div>  
  86.                     <div>  
  87.                         <label>文章内容:(必须)</label>  
  88.                     </div>  
  89.                     <div class="post-area">  
  90.                         <textarea rows="15" cols="55" name="tougao_content"></textarea>  
  91.                     </div>  
  92.                     <p>  
  93.                         <input type="hidden" value="send" name="tougao_form" />  
  94.                         <input id="submit" name="submit" type="submit" value="提交文章" />  
  95.                         <input id="reset" name="submit" type="reset" value="重填" />  
  96.                     </p>  
  97.                 </form>  
  98.             </div>  
  99.         </div>  
  100.     </div>  
  101.     <?php endwhile; else: ?>  
  102.     <?php endif; ?>  
  103.     <?php get_footer(); ?>  
复制代码
然后打开wordpress主题根目录下的style.css,将下面代码插入进去,对,,,又是插入!


  1. /***************投稿**************/  
  2. .tougao{background: none repeat scroll 0 0 #FFF;border: 1px solid #DBDBDB;border-radius:5px;clear: both;overflow:hidden;height:auto;}  
  3. .tougao .entryy{ list-style: none outside none;padding: 15px 0 15px 30px;padding: 10px;}.tougao .entryy p{line-height: 26px;padding-left: 10px;}  
  4. #basicinfo p {width:333px;border: 1px solid #CCC;border-radius: 2px;position: relative;text-indent:0px;margin: 0 0 10px;}  
  5. #basicinfo p #cat {border: 0 none;width: 255px;}  
  6. #basicinfo p:hover, #basicinfo p.on {border-color: #BBB;box-shadow: 0 0 4px #DDD;color: #222;}  
  7. #basicinfo p:hover label, #basicinfo p.on label {border-color: #BBB;}  
  8. #basicinfo label {border-bottom-left-radius: 2px;border-right: 1px solid #CCC;border-top-left-radius: 2px;display: inline-block;height: 20px; padding: 4px;line-height: 20px;text-align: right;width:62px;}  
  9. #basicinfo p small {color: #888;font-size: 12px;left: 350px;position: absolute;}  
  10. #basicinfo input {border: 0 none;border-radius: 2px ;height: 20px;line-height: 20px;padding: 4px;width: 250px;color: #444;font-family: microsoft yahei,verdana,arial;font-size: 12px;outline: medium none;}  
  11. .post-area {background: none repeat scroll 0 0 #FFF;border-radius: 2px;margin-bottom: 10px;position: relative;}  
  12. .post-area  textarea {background: none repeat scroll 0 0 transparent;border: medium none;height: 98px;line-height: 20px;padding: 4px 6px;position: relative;width: 98%;z-index: 2;min-height:320px;border: 1px solid #CCC;}  
  13. .tougao .entryy p input#submit{ -moz-transition: all 0.1s ease-out 0s;border: 1px solid #016EBD;border-radius: 3px;display: inline-block;padding: 5px 15px 6px;text-align: center;background-color: #4D90FE;background-image: -moz-linear-gradient(#049CDB, #0179D2);box-shadow: 0 1px 1px #E6E6E6, 0 1px 0 #36AFE2 inset;color: #FFFFFF;text-shadow: 0 0 1px #016EBD;cursor:pointer;width:auto;}  
  14. .tougao .entryy p input#reset{ -moz-transition: all 0.1s ease-out 0s;background-color: #F9F9F9;background-image: -moz-linear-gradient(#F9F9F9, #F1F1F1);border: 1px solid #CCC;border-radius: 3px;box-shadow: 0 1px 1px #E6E6E6, 0 1px 0 #FFF inset;color: #444;display: inline-block;padding: 5px 15px 6px;text-align: center;text-shadow: 0 0 1px #FEFEFE;cursor:pointer;width:auto;}  
  15. .tougao .entryy p #submit:hover, .tougao .entryy p #reset:hover {color:red;}  
复制代码
只需两步,轻松完成wordpress投稿功能!然后新建页面,选择投稿页面即可!!!
大家会发现,编写正文的时候木有编辑按钮选项,小编是考虑到一些被上传乱七八糟附件,所以没加!!!如果有需要,那么开始新的教程!!!
同样是在wordpress主题根目录新建tougao.php,然后插入下面的代码!
  1. <?php  
  2. /*
  3. * itbobo / admin.itbobo.com / [url]www.itbobo.com[/url] / 2012.03.05
  4.     Template Name: 投稿页面
  5. */  
  6. if( isset($_POST['tougao_form']) && $_POST['tougao_form'] == 'send'){  
  7.     if( isset($_COOKIE["tougao"]) && ( time() - $_COOKIE["tougao"] ) < 120 ){  
  8.         wp_die('您投稿也太勤快了吧,先歇会儿!');  
  9.     }  
  10.     //表单变量初始化  
  11.     $name = isset( $_POST['tougao_authorname'] ) ? $_POST['tougao_authorname'] : '';  
  12.     $email = isset( $_POST['tougao_authoremail'] ) ? $_POST['tougao_authoremail'] : '';  
  13.     $blog = isset( $_POST['tougao_authorblog'] ) ? $_POST['tougao_authorblog'] : '';  
  14.     $title = isset( $_POST['tougao_title'] ) ? $_POST['tougao_title'] : '';  
  15.     $tags = isset( $_POST['tougao_tags'] ) ? $_POST['tougao_tags'] : '';  
  16.     $category = isset( $_POST['cat'] ) ? (int)$_POST['cat'] : 0;  
  17.     $content = isset( $_POST['tougao_content'] ) ? $_POST['tougao_content'] : '';  
  18.     //表单项数据验证  
  19.     if ( emptyempty($name) || strlen($name) > 20 ){  
  20.         wp_die('昵称必须填写,且不得超过20个长度');  
  21.     }  
  22.     if ( emptyempty($email) || strlen($email) > 60 || !preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)){  
  23.         wp_die('邮箱必须填写,且不得超过60个长度,必须符合 Email 格式');  
  24.     }  
  25.     if ( emptyempty($title) || strlen($title) > 100 ){  
  26.         wp_die('文章标题必须填写,且不得超过100个长度');  
  27.     }  
  28.     if ( emptyempty($content) || strlen($content) < 100){  
  29.         wp_die('内容必须填写,且不得少于100个长度');  
  30.     }  
  31.     $tougao = array('post_title' => $title,'post_content' => $content,'post_status' => 'pending','tags_input' => $tags,'post_category' => array($category));  

  32.     $status = wp_insert_post( $tougao );//将文章插入数据库  
  33.     if ($status != 0){  
  34.         global $wpdb;  
  35.         $myposts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'pending' AND post_type = 'post' ORDER BY post_date DESC");  
  36.         add_post_meta($myposts[0]->ID, 'tcp_postauthor', $name);    //插入投稿人昵称的自定义域  
  37.         if( !emptyempty($blog))  
  38.             add_post_meta($myposts[0]->ID, 'tcp_posturl', $blog);    //插入投稿人网址的自定义域  
  39.         setcookie("tougao", time(), time()+180);  
  40.         wp_die('投稿成功!','投稿成功!');  
  41.     }else{  
  42.         wp_die('投稿失败!','投稿失败!');  
  43.     }  
  44. }  
  45. get_header();  
  46. ?>  
  47. <body>  
  48.     <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/kindeditor/kindeditor-min.js"></script>  
  49.     <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/kindeditor/lang/zh_CN.js"></script>  
  50.     <script type="text/javascript">  
  51.             var editor;  
  52.             KindEditor.ready(function(K) {  
  53.                 editor = K.create('textarea[name="tougao_content"]', {  
  54.                     allowFileManager : false,  
  55.                     allowImageUpload : false,  
  56.                 });  
  57.             });  
  58.     </script>  
  59.     <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>  
  60.     <div id="wrapper" class="clearfix">  
  61.         <div class="tougao divmargin">  
  62.             <div class="entry" style="background-color: #FFF8D9;border: 1px solid #FEBE8F;border-radius: 2px;color: #FF6600;padding:5px;margin:10px 10px 0px 10px;font-size:13px;">  
  63.                 <?php the_content('More &#187;'); ?>  
  64.             </div>  
  65.             <div class="entry">  
  66.                 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">  
  67.                     <div id="basicinfo">  
  68.                         <p>  
  69.                             <label>昵称:</label>  
  70.                             <input type="text" value="" name="tougao_authorname" />  
  71.                             <small>*</small>  
  72.                         </p>  
  73.                         <p>  
  74.                             <label>E-Mail:</label>  
  75.                             <input type="text" value="" name="tougao_authoremail" />  
  76.                             <small>*</small>  
  77.                         </p>  
  78.                         <p>  
  79.                             <label>您的网站:</label>  
  80.                             <input type="text" value="" name="tougao_authorblog" />  
  81.                         </p>  
  82.                         <p>  
  83.                             <label>文章标题:</label>  
  84.                             <input type="text" value="" name="tougao_title" />  
  85.                             <small>*</small>  
  86.                         </p>  
  87.                         <p>  
  88.                             <label>文章分类:</label>  
  89.                             <?php wp_dropdown_categories('show_count=1&hierarchical=1'); ?>  
  90.                             <small>*</small>  
  91.                         </p>  
  92.                         <p>  
  93.                             <label>关键字:</label>  
  94.                             <input type="text" value="" name="tougao_tags" />  
  95.                             <small>*</small>  
  96.                         </p>  
  97.                     </div>  
  98.                     <div>  
  99.                         <label>文章内容:(必须)</label>  
  100.                     </div>  
  101.                     <div class="post-area">  
  102.                         <textarea rows="15" cols="55" name="tougao_content"></textarea>  
  103.                     </div>  
  104.                     <p>  
  105.                         <input type="hidden" value="send" name="tougao_form" />  
  106.                         <input id="submit" name="submit" type="submit" value="提交文章" />  
  107.                         <input id="reset" name="submit" type="reset" value="重填" />  
  108.                     </p>  
  109.                 </form>  
  110.             </div>  
  111.         </div>  
  112.     </div>  
  113.     <?php endwhile; else: ?>  
  114.     <?php endif; ?>  
  115.     <?php get_footer(); ?>  
复制代码
将下面的CSS放进wordpress主题根目录style.css里


  1. /***************投稿**************/  
  2. .tougao{background: none repeat scroll 0 0 #FFF;border: 1px solid #DBDBDB;border-radius:5px;clear: both;overflow:hidden;height:auto;}  
  3. .tougao .entry{ list-style: none outside none;padding: 15px 0 15px 30px;padding: 10px;}  
  4. #basicinfo p {width:333px;border: 1px solid #CCC;border-radius: 2px;position: relative;text-indent:0px;margin: 0 0 10px;}  
  5. #basicinfo p #cat {border: 0 none;width: 255px;}  
  6. #basicinfo p:hover, #basicinfo p.on {border-color: #BBB;box-shadow: 0 0 4px #DDD;color: #222;}  
  7. #basicinfo p:hover label, #basicinfo p.on label {border-color: #BBB;}  
  8. #basicinfo label {border-bottom-left-radius: 2px;border-right: 1px solid #CCC;border-top-left-radius: 2px;display: inline-block;height: 20px; padding: 4px;line-height: 20px;text-align: right;width:62px;}  
  9. #basicinfo p small {color: #888;font-size: 12px;left: 336px;position: absolute;}  
  10. #basicinfo input {border: 0 none;border-radius: 2px ;height: 20px;line-height: 20px;padding: 4px;width: 250px;color: #444;font-family: microsoft yahei,verdana,arial;font-size: 12px;outline: medium none;}  
  11. .post-area {background: none repeat scroll 0 0 #FFF;border-radius: 2px;margin-bottom: 10px;position: relative;}  
  12. .post-area  textarea {background: none repeat scroll 0 0 transparent;border: medium none;height: 98px;line-height: 20px;padding: 4px 6px;position: relative;width: 98%;z-index: 2;min-height:320px;}  
  13. .tougao .entry p input#submit{ -moz-transition: all 0.1s ease-out 0s;border: 1px solid #016EBD;border-radius: 3px;display: inline-block;padding: 5px 15px 6px;text-align: center;background-color: #4D90FE;background-image: -moz-linear-gradient(#049CDB, #0179D2);box-shadow: 0 1px 1px #E6E6E6, 0 1px 0 #36AFE2 inset;color: #FFFFFF;text-shadow: 0 0 1px #016EBD;cursor:pointer;width:auto;}  
  14. .tougao .entry p input#reset{ -moz-transition: all 0.1s ease-out 0s;background-color: #F9F9F9;background-image: -moz-linear-gradient(#F9F9F9, #F1F1F1);border: 1px solid #CCC;border-radius: 3px;box-shadow: 0 1px 1px #E6E6E6, 0 1px 0 #FFF inset;color: #444;display: inline-block;padding: 5px 15px 6px;text-align: center;text-shadow: 0 0 1px #FEFEFE;cursor:pointer;width:auto;}  
  15. .tougao .entryp #submit:hover, .tougao .entry p #reset:hover {color:red;}  
复制代码

最后将kindeditor富文本编辑器放到wordpress主题根目录下!

下面给出kindeditor富文本编辑器的下载地址!说明下:linux主机下要给予kindeditor文件夹内的attached给予777权限,编辑文件上传配置在php-upload_json.php内修改


kindeditor富文本编辑器下载地址:

http://pan.baidu.com/s/1eMoMk


转帖地址:

http://www.2zzt.com/jcandcj/3708.html




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|ASTRA wordpress主题-免备案主机-免备案服务器 ( 皖ICP备11021047号 )

GMT+8, 2024-3-29 09:53 , Processed in 0.025373 second(s), 10 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表