更新代码

This commit is contained in:
2025-05-10 17:33:54 +08:00
parent 426e583fc9
commit b1356231d4
39 changed files with 33089 additions and 9795 deletions
+16 -6
View File
@@ -25,17 +25,27 @@ class Index extends Base
$articleList = [];
foreach ($articles as $article) {
$cate = $article['cate'];
$cateName = Db::table('yz_article_category')
// 获取分类信息
$cateInfo = Db::table('yz_article_category')
->where('id', $cate)
->where('delete_time', null)
->where('status', 1)
->value('name');
->field('name, image')
->find();
if ($cateName) { // 只添加有效的分类
if (!isset($articleList[$cateName])) {
$articleList[$cateName] = [];
if ($cateInfo) { // 只添加有效的分类
// 如果文章没有图片,使用分类的图片
if (empty($article['image']) && !empty($cateInfo['image'])) {
$article['image'] = $cateInfo['image'];
}
$articleList[$cateName][] = $article;
// 转换发布日期格式为Y-m-d
$article['publishdate'] = date('Y-m-d', $article['publishdate']);
if (!isset($articleList[$cateInfo['name']])) {
$articleList[$cateInfo['name']] = [];
}
$articleList[$cateInfo['name']][] = $article;
}
}