zoukankan      html  css  js  c++  java
  • WordPress使用自定义文章类型实现任意模板的方法和怎么做邮件回复

    主要就是使用了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', '123456789@qq.com'); //发送邮件帐号
    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 = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); $to = trim(get_comment($parent_id)->comment_author_email); $subject = '你在' . get_option("blogname") . '回复被关注啦~';
    $message = '
    <div style=" 502px; height: auto; margin-bottom: 50px; margin-left: auto; margin-right: auto; font-size: 13px; line-height: 14px;">
    <div style=" 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=" 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>

  • 相关阅读:
    MTD NANDFLASH驱动相关知识介绍
    Java 根据当前时间获取明天、当前周的周五、当前月的最后一天
    使用 Spring 进行单元测试
    Centos下MySQL主从同步配置
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
    CentOS 7 配置静态IP
    mysql 配置 utf8 依然乱码
    rabbitMQ Connection timed out
    CentOS 7.0,启用iptables防火墙
    linux注销、关机、重启
  • 原文地址:https://www.cnblogs.com/2881064178dinfeng/p/6156141.html
Copyright © 2011-2022 走看看