更新代码
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user