文章的侧边栏需要显示标题,但原标题太长了,显示出来不美观。截取一部分吧截取出来的部分又是表达不出意思 索性给数据库增加个短标题字段,侧边栏显示短标题就ok
来源于互联网,仅作为记录
<p><input type="text" name="stitle" value="<?php $post->stitle(); ?>"/></p>
public function writePost()
{
$contents = $this->request->from('password', 'allowComment',
'allowPing', 'allowFeed', 'slug', 'tags', 'text', 'visibility','stitle');
4.1 var/ Widget/ Abstract/ Contents.php 这里的 insert 函数添加新参数:
/**
* 插入内容
*
* @access public
* @param array $content 内容数组
* @return integer
*/
public function insert(array $content)
{
/** 构建插入结构 */
$insertStruct = array(
'title' => empty($content['title']) ? NULL : htmlspecialchars($content['title']),
'created' => empty($content['created']) ? $this->options->gmtTime :$content['created'],
'modified' => $this->options->gmtTime,
'text' => empty($content['text']) ? NULL : $content['text'],
'order' => empty($content['order']) ? 0 : intval($content['order']),
'authorId' => isset($content['authorId']) ? $content['authorId'] : $this->user->uid,
'template' => empty($content['template']) ? NULL : $content['template'],
'type' => empty($content['type']) ? 'post' : $content['type'],
'status' => empty($content['status']) ? 'publish' : $content['status'],
'password' => empty($content['password']) ? NULL : $content['password'],
'commentsNum' => empty($content['commentsNum']) ? 0 : $content['commentsNum'],
'allowComment' => !empty($content['allowComment']) && 1 == $content['allowComment'] ? 1 : 0,
'allowPing' => !empty($content['allowPing']) && 1 == $content['allowPing'] ? 1 : 0,
'allowFeed' => !empty($content['allowFeed']) && 1 == $content['allowFeed'] ? 1 : 0,
'parent' => empty($content['parent']) ? 0 : intval($content['parent']),
'stitle' => empty($content['stitle']) ? NULL : $content['stitle']
);
4.2 在update函数里构建更新结构加入新字段:
/**
* 更新内容
*
* @access public
* @param array $content 内容数组
* @param Typecho_Db_Query $condition 更新条件
* @return integer
*/
public function update(array $content, Typecho_Db_Query $condition)
{
/** 首先验证写入权限 */
if (!$this->isWriteable(clone $condition)) {
return false;
}
/** 构建更新结构 */
$preUpdateStruct = array(
'title' => empty($content['title']) ? NULL : htmlspecialchars($content['title']),
'order' => empty($content['order']) ? 0 : intval($content['order']),
'text' => empty($content['text']) ? NULL : $content['text'],
'template' => empty($content['template']) ? NULL : $content['template'],
'type' => empty($content['type']) ? 'post' : $content['type'],
'status' => empty($content['status']) ? 'publish' : $content['status'],
'password' => empty($content['password']) ? NULL : $content['password'],
'allowComment' => !empty($content['allowComment']) && 1 == $content['allowComment'] ? 1 : 0,
'allowPing' => !empty($content['allowPing']) && 1 == $content['allowPing'] ? 1 : 0,
'allowFeed' => !empty($content['allowFeed']) && 1 == $content['allowFeed'] ? 1 : 0,
'parent' => empty($content['parent']) ? 0 : intval($content['parent']),
'stitle' => empty($content['stitle']) ? NULL : $content['stitle'],
);
4.3 select函数里添加查询新字段:
/**
* 获取查询对象
*
* @access public
* @return Typecho_Db_Query
*/
public function select()
{
return $this->db->select('table.contents.cid', 'table.contents.title', 'table.contents.slug', 'table.contents.created', 'table.contents.authorId',
'table.contents.modified', 'table.contents.type', 'table.contents.status', 'table.contents.text', 'table.contents.commentsNum', 'table.contents.order',
'table.contents.template', 'table.contents.password', 'table.contents.allowComment', 'table.contents.allowPing', 'table.contents.allowFeed',
'table.contents.parent','table.contents.stitle')->from('table.contents');
}