add 分类图片获取

This commit is contained in:
浪子
2024-07-04 20:02:06 +08:00
parent 2b595583c1
commit d1e6567cc9
3 changed files with 31 additions and 25 deletions
+20 -11
View File
@@ -12,17 +12,26 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<h2 class="post--single__subtitle"><?php $this->content(); ?> </h2>
</header>
<section class="category--list">
<?php $this->widget('Widget_Metas_Category_List')->parse('
<div class="category--item">
<img src="https://static.fatesinger.com/2021/12/vhp6eou5x2wqh2zy.jpg" class="category--cover"/>
<div class="category--content">
<a href="{permalink}" class="category--card">{name}
<span>({count})</span>
</a>
<div class="category--desc">{description}</div>
</div>
</div>
'); ?>
<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
<?php while($categories->next()): ?>
<?php
// 获取分类 ID
$categoryId = $categories->mid;
// 获取主题URL
$themeUrl = $this->options->themeUrl;
// 为每个分类生成图片地址
$categoryImage = $themeUrl . 'img/' . $categoryId . '.jpg';
?>
<div class="category--item">
<img class="category--cover" src="<?php echo $categoryImage; ?>" loading="lazy" alt="<?php $categories->name(); ?>">
<div class="category--content">
<a class="category--card" href="<?php $categories->permalink(); ?>"><?php $categories->name(); ?>
<span>(<?php $categories->count(); ?>)</span></a>
<div class="category--desc"> <?php $categories->description(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
</section>
</div>
<?php $this->need('footer.php'); ?>