中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

WordPress網站添加在線投稿發(fā)布功能,帶WP富文本編輯框

2018-11-01    來源:學做網站論壇

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

我們自己建網站過程中,使用的很多程序是沒有自帶的投稿,發(fā)布頁面,需要我們自己去做這樣的頁面,其實并不復雜,按照下面的步驟,你就可以在學做網站過程中做出類似的投稿頁面和發(fā)布頁面了。

以下是學做網站論壇講解的網站如何添加在線投稿發(fā)布功能視頻教程

  • 1、首先在當前主題的目錄下新建一個php文件,命名為tougao.php,然后將page.php中的所有代碼復制到tougao.php中;【相關教程:wordpress模板制作教程】
  • 2、刪除tougao.php開頭的所有注釋,即 /* 與 */ ,以及它們之間的所有內容;
  • 3、搜索:the_content,可以查找到類似代碼<?php the_content(); ?>,將其替換為下面的代碼:
    <?php the_content(); ?>
    ?<!-- 關于表單樣式,請自行調整-->
    ?<form class="ludou-tougao" method="post" action="<?php echo $_SERVER["REQUEST_URI"]; $current_user = wp_get_current_user(); ?>">
    ?
    ?
    ?<div style="text-align: left; padding-top: 10px;">
    ?<label for="tougao_title">標題:*</label><br/>
    ?<input style="width:80%;height:30px;line-height:30px" type="text" size="40" value="" id="tougao_title" name="tougao_title" />
    ?</div>
    ?<div style="text-align: left; padding-top: 10px;">
    ?<label style="vertical-align:top" for="tougao_content">內容:*</label><br/>
    ?<textarea style="width:80%;height:300px" rows="15" cols="55" id="tougao_content" name="tougao_content"></textarea>
    ?</div>
    ?
    ?<div class="feilei" style="text-align: left; padding-top: 10px;">
    ?<label for="tougaocategorg">分類:*</label><br/>
    ?<?php wp_dropdown_categories('hide_empty=0&id=tougaocategorg&show_count=1&hierarchical=1&include=84'); ?>
    ?</div>
    ?
    ?<div style="text-align: left; padding-top: 10px;">
    ?<label for="tougao_authorname">昵稱:*</label><br/>
    ?<input style="width:80%;height:30px;line-height:30px" type="text" size="40" value="<?php if ( 0 != $current_user->ID ) echo $current_user->user_login; ?>" id="tougao_authorname" name="tougao_authorname" />
    ?</div>
    ?
    ?<div style="text-align: left; padding-top: 10px;">
    ?<label for="tougao_authoremail">郵箱:*</label><br/>
    ?<input style="width:80%;height:30px;line-height:30px" type="text" size="40" value="<?php if ( 0 != $current_user->ID ) echo $current_user->user_email; ?>" id="tougao_authoremail" name="tougao_authoremail" />
    ?</div>
    ?
    ?
    ?<br clear="all">
    ?<div style="text-align: center; padding-top: 10px;">
    ?<input type="hidden" value="send" name="tougao_form" />
    ?<input style="width:100px;height:30px;line-height:30px;background:#39F;color:#FFF" type="submit" value="提交" />
    ?<input style="width:100px;height:30px;line-height:30px;background:#39F;color:#FFF" type="reset" value="重填" />
    ?</div>
    ?</form>
  • 4、在tougao.php開頭,將第一個 <?php (一般為:< ?php get_header(); ? >)替換成下面的代碼:
    <?php
    /**
    * Template Name: 發(fā)布模板
    * 作者:學做網站論壇
    * 博客:https://www.xuewangzhan.com/
    */if( isset($_POST['tougao_form']) && $_POST['tougao_form'] == 'send') {
    global $wpdb;
    $current_url = 'https://www.xuewangzhan.com/'; // 注意修改此處的鏈接地址$last_post = $wpdb->get_var("SELECT `post_date` FROM `$wpdb->posts` ORDER BY `post_date` DESC LIMIT 1");// 表單變量初始化
    $name = isset( $_POST['tougao_authorname'] ) ? trim(htmlspecialchars($_POST['tougao_authorname'], ENT_QUOTES)) : '';
    $email = isset( $_POST['tougao_authoremail'] ) ? trim(htmlspecialchars($_POST['tougao_authoremail'], ENT_QUOTES)) : '';
    $blog = isset( $_POST['tougao_authorblog'] ) ? trim(htmlspecialchars($_POST['tougao_authorblog'], ENT_QUOTES)) : '';
    $title = isset( $_POST['tougao_title'] ) ? trim(htmlspecialchars($_POST['tougao_title'], ENT_QUOTES)) : '';
    $category = isset( $_POST['cat'] ) ? (int)$_POST['cat'] : 0;
    $content = isset( $_POST['tougao_content'] ) ? trim(htmlspecialchars($_POST['tougao_content'], ENT_QUOTES)) : '';// 表單項數(shù)據(jù)驗證
    if ( empty($name) || mb_strlen($name) > 20 ) {
    wp_die('昵稱必須填寫,且長度不得超過20字。<a href="'.$current_url.'">點此返回</a>');
    }

    if ( empty($email) || strlen($email) > 60 || !preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)) {
    wp_die('Email必須填寫,且長度不得超過60字,必須符合Email格式。<a href="'.$current_url.'">點此返回</a>');
    }

    if ( empty($title) || mb_strlen($title) > 100 ) {
    wp_die('標題必須填寫,且長度不得超過100字。<a href="'.$current_url.'">點此返回</a>');
    }

    if ( empty($content) || mb_strlen($content) > 3000 || mb_strlen($content) < 100) {
    wp_die('內容必須填寫,且長度不得超過3000字,不得少于100字。<a href="'.$current_url.'">點此返回</a>');
    }

    $post_content = '昵稱: '.$name.'<br />Email: '.$email.'<br />blog: '.$blog.'<br />內容:<br />'.$content;

    $tougao = array(
    'post_title' => $title,
    'post_content' => $post_content,
    'post_category' => array($category)
    );

    // 將文章插入數(shù)據(jù)庫
    $status = wp_insert_post( $tougao );

    if ($status != 0) {
    // 投稿成功給博主發(fā)送郵件
    // somebody#example.com替換博主郵箱
    // My subject替換為郵件標題,content替換為郵件內容
    wp_mail("somebody#example.com","My subject","content");

    wp_die('投稿成功!感謝投稿!<a href="'.$current_url.'">點此返回</a>', '投稿成功');
    }
    else {
    wp_die('投稿失!<a href="'.$current_url.'">點此返回</a>');
    }
    } get_header();?>
  • 5、最后以UTF-8編碼保存tougao.php,否則中文可能會亂碼。然后進入WordPress管理后臺 – 頁面 – 創(chuàng)建頁面,標題為投稿(可以自己起名),內容填上投稿說明等,右側可以選擇模板,選擇 “發(fā)布模板”即可。
  • 6、如果你覺得本文提供的文章編輯框太過單調,需要一個富文本編輯,(相關問題:網站編輯器到底用百度編輯器還是kindeditor)你可以看看這篇文章(包含圖片上傳功能)。帶WP富文本編輯框的在線投稿發(fā)布功能頁面,
    • 一、下載KindEditor (下載地址:http://kindeditor.net/down.php )這里我們將使用KindEditor來作為我們的編輯器,點此下載KindEditor。下載后解壓,將文件夾重命名為kindeditor,放到你當前主題文件夾下。(kindeditor官網如果無法下載,可在此處下載:https://pan.baidu.com/s/1dF89Dwl)
    • 二、?將代碼一中第41行的</form>改成:
      </form>
      <script charset="utf-8" src="<?php bloginfo('template_url'); ?>/kindeditor/kindeditor-min.js"></script>
      <script charset="utf-8" src="<?php bloginfo('template_url'); ?>/kindeditor/lang/zh_CN.js"></script>
      <script>
      /* 編輯器初始化代碼 start */
      var editor;
      KindEditor.ready(function(K) {
      editor = K.create('#tougao_content', {
      resizeType : 1,
      allowPreviewEmoticons : false,
      allowImageUpload : true, /* 開啟圖片上傳功能,不需要就將true改成false */
      items : [
      'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
      'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
      'insertunorderedlist', '|', 'emoticons', 'image', 'link']
      });
      });
      /* 編輯器初始化代碼 end */
      </script>
  • 三、繼續(xù)對tougao.php代碼進行修改。 將代碼一中第41行的:
    $content = isset( $_POST['tougao_content'] ) ? trim(htmlspecialchars($_POST['tougao_content'], ENT_QUOTES)) : '';

    改成下面代碼:

    $content = isset( $_POST['tougao_content'] ) ? trim($_POST['tougao_content']) : '';
    $content = str_ireplace('?>', '?&gt;', $content);
    $content = str_ireplace('<?', '&lt;?', $content);
    $content = str_ireplace('<script', '&lt;script', $content);
    $content = str_ireplace('<a ', '<a rel="external nofollow" ', $content);
  • 四、修改富文本編輯框樣式: 如果你覺得以上自己做的編輯框不符合自己的要求,那就換其它的樣式。我們下載的kindeditor目錄下有個examples文件夾,這里是部分演示,雙擊打開index.html可以看到所有演示。你是否看中某個演示呢?那就用文本編輯器打開它的html文件,查看里面的代碼。這些html文件的代碼中都可以看到類似代碼:
    <script charset="utf-8" src="../kindeditor-min.js"></script>
    <script charset="utf-8" src="../lang/zh_CN.js"></script>
    <script>
    ... 編輯器初始化代碼
    </script>

    將以上代碼中 編輯器初始化代碼 那部分代碼替換第三步中的編輯器初始化代碼,然后將 'textarea[name="content"]' ,改成 '#tougao_content' 即可。

標簽: isp 代碼 建網站 數(shù)據(jù)庫 搜索

版權申明:本站文章部分自網絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:網站空間DB、LOG、WEB三個文件夾作用各是什么

下一篇:網站動態(tài)favicon.ico圖標如何制作