也想出現在這里?聯系我們

最近從ITbobo那移植來的wordpress投稿功能,分享給大家!

  • 文章介紹
  • 升級版本
  • 評價&建議

之前本站有發布過一款仿新版蛋花兒主題,這款wordpress主題得到很多朋友的喜歡,可收到很多朋友的反饋說是要增加wordpress投稿功能,當時忙于其他的事情,一直沒顧及上這款wordpress主題的維護工作!

而最近經常收到一些投稿主題的郵件,也是因為本站沒有一個wordpress投稿功能,所以一直用發郵件代替著,其實小編知道有很多的投稿插件,但是小編一直提倡遠離插件,提升速度的口號!

于是小編前些天從好友ITbobo主題里移植了其wordpress投稿功能,感覺十分的強大,純代碼完成!效率高!也易于使用!

20130726092250

不多說哈,開始教程啦!

首先在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. ??
  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. ????<?php?if?(have_posts())?:??><?php?while?(have_posts())?:?the_post();??>???
  49. ????<div?id="wrapper"?class="clearfix">??
  50. ????????<div?class="tougao?divmargin">??
  51. ????????????<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;">??
  52. ????????????????<?php?the_content('More?&raquo;');??>??
  53. ????????????</div>??
  54. ????????????<div?class="entryy">??
  55. ????????????????<form?method="post"?action="<?php?echo?$_SERVER["REQUEST_URI"];??>">??
  56. ????????????????????<div?id="basicinfo">??
  57. ????????????????????????<p>??
  58. ????????????????????????????<label>作者昵稱:</label>??
  59. ????????????????????????????<input?type="text"?value=""?name="tougao_authorname"?/>??
  60. ????????????????????????????<small>*</small>??
  61. ????????????????????????</p>??
  62. ????????????????????????<p>??
  63. ????????????????????????????<label>E-Mail:</label>??
  64. ????????????????????????????<input?type="text"?value=""?name="tougao_authoremail"?/>??
  65. ????????????????????????????<small>*</small>??
  66. ????????????????????????</p>??
  67. ????????????????????????<p>??
  68. ????????????????????????????<label>您的網站:</label>??
  69. ????????????????????????????<input?type="text"?value=""?name="tougao_authorblog"?/>??
  70. ????????????????????????</p>??
  71. ????????????????????????<p>??
  72. ????????????????????????????<label>文章標題:</label>??
  73. ????????????????????????????<input?type="text"?value=""?name="tougao_title"?/>??
  74. ????????????????????????????<small>*</small>??
  75. ????????????????????????</p>??
  76. ????????????????????????<p>??
  77. ????????????????????????????<label>文章分類:</label>??
  78. ????????????????????????????<?php?wp_dropdown_categories('show_count=1&hierarchical=1');??>??
  79. ????????????????????????????<small>*</small>??
  80. ????????????????????????</p>??
  81. ????????????????????????<p>??
  82. ????????????????????????????<label>關鍵詞:</label>??
  83. ????????????????????????????<input?type="text"?value=""?name="tougao_tags"?/>??
  84. ????????????????????????????<small>*</small>??
  85. ????????????????????????</p>??
  86. ????????????????????</div>??
  87. ????????????????????<div>??
  88. ????????????????????????<label>文章內容:(必須)</label>??
  89. ????????????????????</div>??
  90. ????????????????????<div?class="post-area">??
  91. ????????????????????????<textarea?rows="15"?cols="55"?name="tougao_content"></textarea>??
  92. ????????????????????</div>??
  93. ????????????????????<p>??
  94. ????????????????????????<input?type="hidden"?value="send"?name="tougao_form"?/>??
  95. ????????????????????????<input?id="submit"?name="submit"?type="submit"?value="提交文章"?/>??
  96. ????????????????????????<input?id="reset"?name="submit"?type="reset"?value="重填"?/>??
  97. ????????????????????</p>??
  98. ????????????????</form>??
  99. ????????????</div>??
  100. ????????</div>??
  101. ????</div>??
  102. ????<?php?endwhile;?else:??>??
  103. ????<?php?endif;??>??
  104. ????<?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. ????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. ??
  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. ????<div?class="nyadtop">??
  48. ????????<a?href="http://www.breathecast.cn/theme-customization"?target="_blank"><img?alt="wordpress主題定制"?title="wordpress主題定制"?src="<?php?bloginfo('template_directory');??>/images/nyadtop.png"></a>??
  49. ????</div>??
  50. <body>??
  51. ????<script?type="text/javascript"?src="<?php?bloginfo('template_url');??>/kindeditor/kindeditor-min.js"></script>??
  52. ????<script?type="text/javascript"?src="<?php?bloginfo('template_url');??>/kindeditor/lang/zh_CN.js"></script>??
  53. ????<script?type="text/javascript">??
  54. ????????????var?editor;??
  55. ????????????KindEditor.ready(function(K)?{??
  56. ????????????????editor?=?K.create('textarea[name="tougao_content"]',?{??
  57. ????????????????????allowFileManager?:?false,??
  58. ????????????????????allowImageUpload?:?false,??
  59. ????????????????});??
  60. ????????????});??
  61. ????</script>??
  62. ????<?php?if?(have_posts())?:??><?php?while?(have_posts())?:?the_post();??>???
  63. ????<div?id="wrapper"?class="clearfix">??
  64. ????????<div?class="tougao?divmargin">??
  65. ????????????<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;">??
  66. ????????????????<?php?the_content('More?&raquo;');??>??
  67. ????????????</div>??
  68. ????????????<div?class="entry">??
  69. ????????????????<form?method="post"?action="<?php?echo?$_SERVER["REQUEST_URI"];??>">??
  70. ????????????????????<div?id="basicinfo">??
  71. ????????????????????????<p>??
  72. ????????????????????????????<label>昵稱:</label>??
  73. ????????????????????????????<input?type="text"?value=""?name="tougao_authorname"?/>??
  74. ????????????????????????????<small>*</small>??
  75. ????????????????????????</p>??
  76. ????????????????????????<p>??
  77. ????????????????????????????<label>E-Mail:</label>??
  78. ????????????????????????????<input?type="text"?value=""?name="tougao_authoremail"?/>??
  79. ????????????????????????????<small>*</small>??
  80. ????????????????????????</p>??
  81. ????????????????????????<p>??
  82. ????????????????????????????<label>您的網站:</label>??
  83. ????????????????????????????<input?type="text"?value=""?name="tougao_authorblog"?/>??
  84. ????????????????????????</p>??
  85. ????????????????????????<p>??
  86. ????????????????????????????<label>文章標題:</label>??
  87. ????????????????????????????<input?type="text"?value=""?name="tougao_title"?/>??
  88. ????????????????????????????<small>*</small>??
  89. ????????????????????????</p>??
  90. ????????????????????????<p>??
  91. ????????????????????????????<label>文章分類:</label>??
  92. ????????????????????????????<?php?wp_dropdown_categories('show_count=1&hierarchical=1');??>??
  93. ????????????????????????????<small>*</small>??
  94. ????????????????????????</p>??
  95. ????????????????????????<p>??
  96. ????????????????????????????<label>關鍵字:</label>??
  97. ????????????????????????????<input?type="text"?value=""?name="tougao_tags"?/>??
  98. ????????????????????????????<small>*</small>??
  99. ????????????????????????</p>??
  100. ????????????????????</div>??
  101. ????????????????????<div>??
  102. ????????????????????????<label>文章內容:(必須)</label>??
  103. ????????????????????</div>??
  104. ????????????????????<div?class="post-area">??
  105. ????????????????????????<textarea?rows="15"?cols="55"?name="tougao_content"></textarea>??
  106. ????????????????????</div>??
  107. ????????????????????<p>??
  108. ????????????????????????<input?type="hidden"?value="send"?name="tougao_form"?/>??
  109. ????????????????????????<input?id="submit"?name="submit"?type="submit"?value="提交文章"?/>??
  110. ????????????????????????<input?id="reset"?name="submit"?type="reset"?value="重填"?/>??
  111. ????????????????????</p>??
  112. ????????????????</form>??
  113. ????????????</div>??
  114. ????????</div>??
  115. ????</div>??
  116. ????<?php?endwhile;?else:??>??
  117. ????<?php?endif;??>??
  118. ????<?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內修改

2013/10/12 更新下php文件和css文件,之前有人說代碼有問題,小編這下考慮到可能是編碼或者代碼高亮的問題吧,現在把文件打包了,需要的下載文件包吧!

有用0
  • 2013.07.26初次和大家見面了!

已擁有6人對該主題的建議

  1. 0樓
    dcdc:

    tougao.php運行后有很多個函數未定義

    2014-02-14 下午 8:36 [回復]
    • 恩,這是從ITBOBO那主題扒來的,里面的作者、網址都是新定義的域,需要主題去支持。。。但不影響使用!

      2014-02-15 上午 8:46 [回復]
  2. 0樓
    易膚網:

    老大這個沒有搞成功,能指導一下么

    2014-01-04 下午 5:23 [回復]
  3. 謝謝分享,非常給力!

    2014-01-03 下午 4:12 [回復]
  4. 0樓
    屌絲博:

    果斷就收藏了 謝謝分享··

    2013-07-28 下午 6:15 [回復]
  5. 哇靠。給力!!!!!!

    2013-07-26 下午 3:43 [回復]

發表評論

還能輸入240個字

Hi, 歡迎加入Wordpress技術交流群,帶你裝逼帶你飛!

我要入群
也想出現在這里?聯系我們
wordpress加速

我來推薦一個更牛逼的給你看看?

  • 猛戳我吧
夫妇野外交换HD高清版,免费A片在线观看,亚洲精品国产自在现线,中国老妇人60OLDMANTV