WordPress使用自訂文章類型實現任意模板的方法和怎麼做郵件回複

來源:互聯網
上載者:User

標籤:顯示   item   upd   class   confirm   ras   dmi   iss   create   

主要就是使用了register_post_type 函數。

1、建立外掛程式目錄

建立一個檔案夾用來存放外掛程式檔案,這裡我就命名這個檔案夾為myMood

2、創php代碼檔案

在剛才建立的檔案夾裡面建立一個php檔案,命名為myMood,用來書寫外掛程式代碼

3、添加頭部描述

複製代碼

代碼如下:<?php
/*
Plugin Name: Movie Reviews
Plugin URI: http://wp.tutsplus.com/
Description: Declares a plugin that will create a new post type .
Version: 1.0
Author: Summer
Author URI: http://www.xtwind.com/
License: GPLv2
*/
?>
4、註冊自訂函數
在剛剛建立的php檔案代碼中,在?>前面添加函數:

複製代碼

代碼如下:

add_action( ‘init‘, ‘create_myMood‘ );

得到如下代碼:

複製代碼

代碼如下:<?php
/*
Plugin Name: Movie Reviews
Plugin URI: http://wp.tutsplus.com/
Description: Declares a plugin that will create a new post type .
Version: 1.0
Author: Summer
Author URI: http://www.xtwind.com/
License: GPLv2
*/
add_action( ‘init‘, ‘create_myMood‘ );
?>
5、添加函數功能
把下面這段代碼添加到 add_action( ‘init‘, ‘create_myMood‘ ); 的前面

複製代碼

代碼如下:function create_lsxq() {
register_post_type( ‘lsxq‘,
array(
‘labels‘ => array(
‘name‘ => ‘零散心情‘,
‘singular_name‘ => ‘lsxq‘,
‘add_new‘ => ‘寫心情‘,
‘add_new_item‘ => ‘添加一條新心情‘,
‘edit‘ => ‘Edit‘,
‘edit_item‘ => ‘Edit lsxq‘,
‘new_item‘ => ‘New lsxq‘,
‘view‘ => ‘View‘,
‘view_item‘ => ‘View lsxq‘,
‘search_items‘ => ‘Search lsxq‘,
‘not_found‘ => ‘No lsxq found‘,
‘not_found_in_trash‘ => ‘No lsxq found in Trash‘,
‘parent‘ => ‘Parent lsxq‘
),
‘public‘ => true,
‘menu_position‘ => 15,
‘supports‘ => array( ‘title‘, ‘editor‘, ‘comments‘, ‘thumbnail‘ ),
‘taxonomies‘ => array( ‘‘ ),
‘menu_icon‘ => plugins_url( ‘images/image.png‘, __FILE__ ),
‘has_archive‘ => true
)
);
}

對 register_post_type 這個函數發出聲明,它就為新的文章類型做好了各種管理功能。這個函數包括兩個參數:第一個是定義了自訂文章類型的名字 ;第二個是一個數組,用來定義新的自訂文章類型的屬性。

第一個參數很簡單,大家自己領悟。這裡簡單說下地位個參數:

‘public‘ => true 決定該文章類型在管理後台和前端的可見度
‘menu_position‘ => 5 決定該文章類型菜單的位置
‘supports‘ => array( ‘title‘, ‘editor‘, ‘comments‘, ‘thumbnail‘) 決定自訂文章類型的功能
‘taxonomies‘ => array( ‘‘ ) 建立自訂分類,這裡沒有定義。
‘menu_icon‘ => plugins_url( ‘image.png‘, __FILE__ ) 顯示管理菜單的表徵圖,表徵圖檔案放在和外掛程式同一目錄,為16*16像素
‘has_archive‘ => true 啟用自訂文章類型的存檔功能

請訪問 register_post_type 瞭解更多關於該函數的參數細節。

function comment_mail_notify($comment_id) {
define(‘MAIL_SMTP‘, ‘smtp.exmail.qq.com‘); //smtp伺服器
define(‘MAIL_PORT‘, 25); //smtp連接埠
define(‘MAIL_SENDEMAIL‘, ‘[email protected]‘); //發送郵件帳號
define(‘MAIL_PASSWORD‘, ‘123456‘); //發送郵件密碼
$admin_notify = ‘1‘;
$admin_email = get_bloginfo (‘admin_email‘);
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : ‘‘;
global $wpdb;
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == ‘‘) $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email && isset($_POST[‘comment_mail_notify‘])) || ($comment_author_email == $admin_email && $admin_notify == ‘1‘)) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify=‘1‘ WHERE comment_ID=‘$comment_id‘");
$notify = $parent_id ? ‘1‘ : ‘0‘;
$spam_confirmed = $comment->comment_approved;
if ($parent_id != ‘‘ && $spam_confirmed != ‘spam‘ && $notify == ‘1‘) { $wp_email = ‘[email protected]‘ . preg_replace(‘#^www\.#‘, ‘‘, strtolower($_SERVER[‘SERVER_NAME‘])); $to = trim(get_comment($parent_id)->comment_author_email); $subject = ‘你在‘ . get_option("blogname") . ‘回複被關注啦~‘;
$message = ‘
<div style="width: 502px; height: auto; margin-bottom: 50px; margin-left: auto; margin-right: auto; font-size: 13px; line-height: 14px;">
<div style="width: 502px; margin-top: 10px;">
<div style="font-size: 16px; color: #373737; text-align: center;">‘.get_bloginfo("name").‘</div>
<div style="font-size: 15px; color: #f0f7eb; padding: 9px; margin-top: 20px; overflow: hidden; background: #299982; padding-left: 30px; padding-right: 40px;">你在 ‘. get_the_title($comment-&gt;comment_post_ID) .‘ 的評論有了回複:</div>
</div>
<div style="width: 420px; margin-top: 30px; padding: 0 40px 20px; border-left: 1px dashed #299982; border-right: 1px dashed #299982; color: rgba(0,0,0,0.7); background: #f9f9f9; overflow: hidden;">
<div class="one origin" style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0;"><span style="color: #299982;">‘. trim(get_comment($parent_id)-&gt;comment_author) .‘</span>:‘. trim(get_comment($parent_id)-&gt;comment_content) .‘</div>
<div class="one reply" style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0 1em 60px;"><span style="color: #299982;">‘. trim($comment-&gt;comment_author) .‘</span>:‘. trim($comment-&gt;comment_content) .‘</div>
<p style="margin-bottom: 10px;">點擊<a href="‘ . htmlspecialchars(get_comment_link($parent_id)) . ‘ style=">查看完整內容</a></p>
<p style="margin-bottom: 10px;">(此郵件由系統發出,無需回複.)</p>
</div>
</div>

WordPress使用自訂文章類型實現任意模板的方法和怎麼做郵件回複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.