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

时间:2020-08-01   阅读:338

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

使用方法:

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

1
2
3
4
5
6
7
8
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);}

效果如下:

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

文章由 博客吧 整理发布


上一篇:Typecho文章自定义字段的使用方法

下一篇:Typecho调用指定数量最新文章的方法代码

网友评论