Typecho二次开发 文章表添加新字段 有时候我们 - Assbbs
Typecho二次开发 文章表添加新字段 有时候我们需要在博客中显示其他功能比如每篇文章可以自定义标题颜色,就需要添加一个标题颜色属性,就必须添加自定义的字段,我这里是添加了一个比如 1.首先数据表 typecho contents 中新建一个test url字段,类型可为字符串。 2.后台模板文件write-post.php 表单中插入: <p>…
Typecho二次开发 文章表添加新字段 有时候我们需要在博客中显示其他功能比如每篇文章可以自定义标题颜色,就需要添加一个标题颜色属性,就必须添加自定义的字段,我这里是添加了一个比如 1.首先数据表 typecho contents 中新建一个test url字段,类型可为字符串。 2.后台模板文件write-post.php 表单中插入: <p><input type="text" name="test url" value="<?php $post->test url ; ?>"/></p> 3.在 Widget\Contents\Post\Edit.php 这里的 writePost 函数里需要接收新字段参数: public function writePost { $contents = $this->request->from & 39;password& 39;, & 39;allowComment& 39;, & 39;allowPing& 39;, & 39;allowFeed& 39;, & 39;slug& 39;, & 39;tags& 39;, & 39;text& 39;, & 39;visibility& 39;,& 39;test url& 39; ; 4.1 Widget\Abstract\Contents.php 这里的 insert 函数添加新参数: / 插入内容 @access public @param array $content 内容数组 @return integer / public function insert array $content { / 构建插入结构 / $insertStruct = array & 39;title& 39; => empty $content & 39;title& 39; ? NULL : htmlspecialchars $content & 39;title& 39; , & 39;created& 39; => empty $content & 39;created& 39; ? $this->options->gmtTime : $content & 39;created& 39; , & 39;modified& 39; => $this->options->gmtTime, & 39;text& 39; => empty $content & 39;text& 39; ? NULL : $content & 39;text& 39; , & 39;order& 39; => empty $content & 39;order& 39; ? 0 : intval $content & 39;order& 39; , & 39;authorId& 39; => isset $content & 39;authorId& 39; ? $content & 39;authorId& 39; : $this->user->uid, &n…