Typecho文章自定义字段添加设置面板函数themeFields

前面介绍了Typecho文章自定义字段的使用方法,但是每次使用自定义字段的时候,都要输入一次字段名称、类型,对于会经常使用的自定义字段,不仅不方便,而且有可能会输入错误,那么有没有给常使用的自定义字段添加一个固定的设置模块,使用的时候只需要输入字段值的方法?为此typecho提供了themefields函数,通过该函数可以为主题增加一个自动绑定的输入框。

使用方法:
主题的functions.php文件,添加以下代码:

function themeFields($layout) {
$title = new Typecho_Widget_Helper_Form_Element_Text('title', NULL, NULL, _t('文章title标题'), _t('SEO设置'));
$keywords = new Typecho_Widget_Helper_Form_Element_Text('keywords', NULL, NULL, _t('文章keywords关键词'), _t('SEO设置'));
$description = new Typecho_Widget_Helper_Form_Element_Text('description', NULL, NULL, _t('文章description描述'), _t('SEO设置'));
$layout->addItem($title);
$layout->addItem($keywords);
$layout->addItem($description);
}

调用
fields->Text(); ?>

发表新评论