解决 1.3.0 版本Typecho 与模板不兼容导致列表报错问题

活学活用  ·  2025-03-26

1、修改文件/www/wwwroot/*/usr/themes/Jasmine-main/template-parts/category-sub.php

<?php use widget\CategorySub;

if (!defined('__TYPECHO_ROOT_DIR__')) exit;

// 确保当前是分类页且有有效 mid
if ($this->is('category') && isset($this->pageRow->mid) && $this->pageRow->mid > 0):
    $parentId = (int)$this->pageRow->mid;
    CategorySub::alloc(['parent' => $parentId])->to($categories);
?>
<?php if ($categories->have()): ?>
    <div class="card border-0 py-1 col-12">
        <div class="d-flex flex-wrap row-gap-2 column-gap-3 sub-category">
            <a class="px-3 py-2" href="<?php $this->archiveUrl(); ?>">
                <?php $this->archiveTitle(); ?>
            </a>
            <?php while ($categories->next()): ?>
                <a class="px-3 py-2" href="<?php $categories->permalink(); ?>">
                    <?php $categories->name(); ?>
                </a>
            <?php endwhile; ?>
        </div>
    </div>
<?php endif; ?>
<?php endif; ?>

2、修改文件/www/wwwroot/*/usr/themes/Jasmine-main/widget/CategorySub.php

<?php

namespace widget;

use Widget\Metas\Category\Rows;

class CategorySub extends Rows {

/**
 * 执行函数
 */
public function execute(){
    // 修复方案:强制转为数组,即使为空
    $categories = $this->getCategories($this->parent);
    $this->stack = is_array($categories) ? $categories : [];
}

}
评论
Jan. All Rights Reserved. Theme Jasmine by Kent Liao.
蜀ICP备2023017538号-1