主机迷主机迷

如何在Typecho后台添加一个自定义设置

有时要在Typecho后台添加一个自定义设置,注意不是在主题里面设置,需要修改var/Widget/Options/General.php。这里以一个自定义设置commentsVerify(评论是否校验)为例。

在General.php的form()函数里添加代码:

 /** 评论是否校验 */
    $commentsVerify = new Typecho_Widget_Helper_Form_Element_Radio('commentsVerify', array('0' => _t('不校验'), '1' => _t('校验')), $this->options->commentsVerify, _t('评论是否校验'));
    $form->addInput($commentsVerify);

在General.php的updateGeneralSettings()函数里获取的参数中添加一个参数commentsVerify:

$settings = $this->request->from('title','description', 'keywords', 'allowRegister', 'commentsVerify', 'allowXmlRpc', 'lang', 'timezone');

另外还需要在typecho_options表中添加一行commentsVerify相关记录,否则保存不了设置。有两个办法,可以在安装时进行初始化,修改install.php,添加一行代码:

$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsVerify', 'user' => 0, 'value' => 0)));

或者手动执行sql:

insert into typecho_options(name,user,value) values ('commentsVerify',0,'1');

自定义的设置如何使用?

<?php if($this->options->commentsVerify): ?>
   ...
<?php endif; ?>
转载请注明出处 | 当前页面:主机迷 » 如何在Typecho后台添加一个自定义设置

评论

  • 请输入 13 + 3 = ? 的计算结果: