首先,我感觉这个功能是一个坑。官方文档也不清不楚,还是搜索资料+摸索吧。
在主题目录 usr/themes/主题目录
下的 functions.php
文件里插入:
function themeFields($layout) {
$keywords_seo = new Typecho_Widget_Helper_Form_Element_Text('keywords_seo', NULL, NULL, _t('SEO 关键词'), _t('文章SEO关键词,以半角,隔开'));//Text 单行输入框
$keywords_seo->input->setAttribute('class', 'w-100');//这是自定义输入框的样式
$description_seo = new Typecho_Widget_Helper_Form_Element_Textarea('description_seo', NULL, NULL, _t('Description 描述'), _t('文章 SEO 的描述'));//Textarea 多行输入框
$description_seo->input->setAttribute('style', 'width:100%;height:100px');//这是自定义输入框的样式
$layout->addItem($keywords_seo);
$layout->addItem($description_seo);
}
添加以上代码后,在发表文章时,多了如下的输入框
然后可以在模板里调用方式如下代码:
<?php if(empty($this->fields->keywords_seo)): ?>自定义字段内容不填写时显示的内容<?php else: ?><?php $this->fields->keywords_seo(); ?><?php endif; ?>
或
<?php if(isset($this->fields->keywords_seo)): ?><?php $this->fields-> keywords_seo(); ?><?php endif; ?>
以上这段代码就是调用自定义字段 $keywords_seo
的内容