主要就是使用了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="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使用自定义文章类型实现任意模板的方法和怎么做邮件回复的更多相关文章

  1. C:Wordpress自定义文章类型(图视频)

    自定义文章类型,包括: 1:单独的"文章内容模板" 2:单独的"文章列表模板" 3:单独的"控制后台"(文章分类.添加文章) 创建自定义文章 ...

  2. wordpress添加post_type自定义文章类型

    wordpress很强大,能当博客也能进行二次开发出很完善的内容管理系统满足企业运营需求,比如可以添加products产品模型.汽车模型等,如何实现呢?添加post_type自定义文章类型就可以了 p ...

  3. Wordpress 自定义文章类型添加 Categoried、Tags

    默认情况下 ,自定义文章类型没有分类和标签属性,需要通过 register_taxonomy_for_object_type 手动注册文章分类和标签,可以通过在 functions.php 或插件中添 ...

  4. WordPress 博客文章中google adsense广告展示方法之一

    http://log.medcl.net/item/2011/08/diving-into-elasticsearch-4-installation-and-configuration/ 看到这个网站 ...

  5. wordpress调用自定义post_type文章

    前面我们讲了wordpress添加post_type自定义文章类型,我们现在来讲一下如何把自定义文章调用出来,我们以product为例,虽然我们自定义好了 Post Type 同时也编写了一些内容,但 ...

  6. Wordpress 后台文章编辑区添加模板选择功能

    功能:后台编辑文章时,可以选择文章使用的模板,效果如下图: 操作步骤: <?php /** * Template Name: kbsingle full * Add by Ryan 3/18/2 ...

  7. wordpress教程之文章页single.php获取当前文章所属分类

    之所以要发这篇文章,是因为这个方法适用于: WP默认文章分类 手动添加的自定文章分类 插件(custom post type ui)添加的自定义文章分类(含taxonomy) 方法目的:在文章模板中, ...

  8. WordPress自定义文章页面模板

    如果想让某个分类的文章页面样式有别于其它分类,我们可以使用自定义的模板的方法实现.例如,我们准备让名称为 WordPress 的分类文章使用有别于其它分类的模板样式, 首先在所用主题根目录新建一个名称 ...

  9. 終于解決调用wordpress 4.3 xmlrpc api 发布包含分类的文章时返回“抱歉,文章类型不支持您的分类法”错误的問題

    這個問題我找了很多資料都沒有明說是如何解決,后來突發奇想得出我的解決方案如下,所以特此記錄一下: object postId = blogService.NewPost(0,"admin&q ...

随机推荐

  1. extern关键字及C\C++相互调用

    extern关键字主要修饰变量或函数,表示该函数可以跨文件访问,或者表明该变量在其他文件定义,在此处引用. 1.extern修饰变量 (1)如果某变量int m在a.c中定义声明,则其他b.c文件访问 ...

  2. vue.js_10_vue的路由

    1.vue-router的基本使用 1>安装vue-rouder路由模块 <script src="js/vue-2.4.0.js"></script> ...

  3. 在Bat批处理中调用Powershell脚本

    ##如何在BAT中调用powershell,把下面代码另存为bat格式pushd %~dp0powershell.exe -command ^  "& {set-executionp ...

  4. 爬虫(四)Selenium + Headless Chrome爬取Bing图片搜索结果

    Bing图片搜索结果是动态加载的,如果我们直接用requests去访问页面爬取数据,那我们只能拿到很少的图片.所以我们使用Selenium + Headless Chrome来爬取搜索结果.在开始前, ...

  5. Redis学习笔记02-消息队列与延时队列

    写在前面:Redis的消息队列并不是专业的消息队列,没有ACK保证,没有特别多的高级特性,如果对消息的可靠性有很高的要求,就放弃它吧. 1.Redis消息队列 Redis通过内部的list数据结构来实 ...

  6. C# 全局Hook在xp上不回调

    最近做了个捕捉全局鼠标,获取目标窗体内的控件文本信息,点击的按钮信息.用的全局钩子.在win10上运行正常,部署到xp系统上就没有反应.查了些资料,解决了此问题. 原本安装钩子的写法如下: Nativ ...

  7. JasperReport查看和打印报告7

    报表填充过程JasperPrint对象的输出可以使用内置的浏览器组件来查看,打印或导出到更多的流行的文件格式,如PDF,HTML,RTF,XLS,ODT,CSV或XML.Jasper文件查看和打印将包 ...

  8. servlet接收request请求的json数据

    此次使用的是alibaba的fastjson:jar包为fastjson-1.2.7.jar 参考:https://www.qingtingip.com/h_229797.html 思路:由于此次接收 ...

  9. Luogu P1092 虫食算(枚举+剪枝)

    P1092 虫食算 题面 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简单的例子: 43#9865#045 + 8468#6633 4 ...

  10. https://vjudge.net/problem/2198221/origin

    https://vjudge.net/problem/2198221/origin逆向思维,原题是人出来,我们处理成人进去,算出来每个人的曼哈顿距离,然后从大到小排序,距离长的先入.走的距离+这个人从 ...