一、添加一個存儲投稿者郵箱的自定義欄目
打開WordPress添加投稿功能,下面我們將對這篇文章中的代碼進行修改。在第二段代碼第78行插入以下代碼:
- // 其中 ludou_tougao_email 是自定義欄目的名稱
- add_post_meta($status, 'ludou_tougao_email', $email, TRUE);
二、添加提醒功能php代碼
在主題目錄下的functions.php添加以下php代碼(將以下代碼中的露兜博客名稱和URL改成你自己的):
- function tougao_notify($mypost) {
- $email = get_post_meta($mypost->ID, "ludou_tougao_email", true);
- if( !empty($email) ) {
- // 以下是郵件標題
- $subject = '您在露兜博客的投稿已發(fā)布';
- // 以下是郵件內(nèi)容
- $message = '
- <p><strong>露兜博客</strong> 提醒您: 您投遞的文章 <strong>' . $mypost->post_title . '</strong> 已發(fā)布</p>
- <p>您可以點擊以下鏈接查看具體內(nèi)容:<br />
- <a href="' . get_permalink( $mypost->ID ) . '">點此查看完整內(nèi)容</a></p>
- <p>===================================================================</p>
- <p><strong>感謝您對 <a href="http://m.ythuaji.com.cn" target="_blank">露兜博客</a> 的關注和支持</strong></p>
- <p><strong>該信件由系統(tǒng)自動發(fā)出, 請勿回復, 謝謝.</strong></p>';
- add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
- @wp_mail( $email, $subject, $message );
- }
- }
- // 當投稿的文章從草稿狀態(tài)變更到已發(fā)布時,給投稿者發(fā)提醒郵件
- add_action('draft_to_publish', 'tougao_notify', 6);
以上功能需要你的服務器支持mail函數(shù)。