酷秀  - kxiu.cn

给你的typecho分类添加缩略图标

admin的头像admin5个月前教程104热度

把下面的代码添加到“functions.php”文件中

 $fenlei = new \Typecho\Widget\Helper\Form\Element\Textarea(
    'fenlei',
    null,
    null,
    _t('分类图标'),
    _t('可以通过这里自定义分类图标,多个请用|进行分隔。列如:http://xx.xx/xx.png|http://xx.xx/xx.png')
);

$form->addInput($fenlei);

模板中分类图标调用代码如下

<?php $fenleiimg = explode('|',rtrim($this->options->fenlei,'|')); ?>
<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?>
<?php $i = 0; while($categorys->next()): ?>
    <a href="<?php $categorys->permalink(); ?>" title="<?php $categorys->name(); ?>">
        <img src="<?php echo $fenleiimg[$i]; ?>">
        <p><?php $categorys->name(); ?></p>
    </a>
<?php $i++; endwhile; ?>
签名: 最忠诚的BUG开发者来自: 重庆市. Chrome浏览器
文章目录

新年快乐

×
新年快乐
同喜