ThinkCMF5 tag页面实现获取文章分类ID category_id 以此实现链接url美化效果

2019-02-27 12:304570

本实例版本为ThinkCMF 5.0.190111 正式版。

修改/app/portal/service/ApiService.php下的tagArticles()方法,部分代码片段修改前后:

if (empty($tagId)) {
    return null;
}else {
// $field = !empty($param['field']) ? $param['field'] : 'post.*';
$field = !empty($param['field']) ? $param['field'] : 'post.*,category_post.category_id as category_id';
//array_push($join, ['__PORTAL_TAG_POST__ tag_post', 'post.id = tag_post.post_id']);
array_push($join, ['__PORTAL_TAG_POST__ tag_post', 'post.id = tag_post.post_id'],['__PORTAL_CATEGORY_POST__ category_post', 'post.id = category_post.post_id']);//by hihelp		
$where['tag_post.tag_id'] = $tagId;
}

然后找到

$articles = $portalPostModel->alias('post')->field($field)

修改为:

$articles = $portalPostModel->alias('post')->group('post.id')->field($field)

group('post.id')去重。

上一篇: PHP array_push() 函数

下一篇: thinkcmf5 获取文件下载链接