diff --git a/app/Helpers/function.php b/app/Helpers/function.php index 99e22cb..0d1e296 100644 --- a/app/Helpers/function.php +++ b/app/Helpers/function.php @@ -57,7 +57,7 @@ function getOneArticleBYCate($categoryId, $result = '') * @param int $recommen * @return \App\Models\Article */ -function getArticlesBYCate($categoryId, $take = 8, $recommen = 0) +function getArticlesBYCate($categoryId, int $take = 8, $recommen = 0) { $cate = Category::find($categoryId); $ids = $cate ? $cate->getAllChildrenId() : []; @@ -75,6 +75,26 @@ function getArticlesBYCate($categoryId, $take = 8, $recommen = 0) return $articles; } +/** + * Notes: 获取有图片的文章 + * + * @Author: 玄尘 + * @Date: 2021/12/20 13:22 + * @param $categoryId + * @param $take + * @return mixed + */ +function getHasCoverArticlesByCate($categoryId, $take = 8) +{ + return Article::where('status', 1) + ->ByCategory([$categoryId]) + ->whereNotNull('cover') + ->latest('sort') + ->latest() + ->take($take) + ->get(); +} + //获取子分类 function getCateChild($categoryId, $take = '') { diff --git a/resources/views/category/djwh.blade.php b/resources/views/category/djwh.blade.php index b1d5944..31913ca 100644 --- a/resources/views/category/djwh.blade.php +++ b/resources/views/category/djwh.blade.php @@ -21,11 +21,14 @@
更多>>
- @if (getArticlesBYCate(60,1)->isNotEmpty()) - @foreach (getArticlesBYCate(60,1) as $info) -
+ @if (getHasCoverArticlesByCate(60,1)->isNotEmpty()) + @foreach (getHasCoverArticlesByCate(60,1) as $info) +
+
+ {{ $info->title }} +
@endforeach @endif @@ -33,7 +36,6 @@ @if (getArticlesBYCate(60,3)->isNotEmpty()) @foreach (getArticlesBYCate(60,3) as $info)
  • -
    @@ -84,11 +86,14 @@
    - @if (getArticlesBYCate(61,1)->isNotEmpty()) - @foreach (getArticlesBYCate(61,1) as $info) -
    + @if (getHasCoverArticlesByCate(61,1)->isNotEmpty()) + @foreach (getHasCoverArticlesByCate(61,1) as $info) +
    +
    + {{ $info->title }} +
    @endforeach @endif @@ -194,4 +199,3 @@
    @endsection - diff --git a/resources/views/category/kxyj.blade.php b/resources/views/category/kxyj.blade.php index 14a38a7..a4be72d 100644 --- a/resources/views/category/kxyj.blade.php +++ b/resources/views/category/kxyj.blade.php @@ -25,11 +25,14 @@
    - @if (getArticlesBYCate(17,1)->isNotEmpty()) - @foreach (getArticlesBYCate(17,1) as $info) -
    + @if (getHasCoverArticlesByCate(17,1)->isNotEmpty()) + @foreach (getHasCoverArticlesByCate(17,1) as $info) +
    +
    + {{ $info->title }} +
    @endforeach @endif @@ -109,19 +112,29 @@
    +
    -
    - - -
    + @if (getHasCoverArticlesByCate(17,1)->isNotEmpty()) + @foreach (getHasCoverArticlesByCate(17,1) as $info) +
    + + +
    + {{ $info->title }} +
    +
    + @endforeach + @endif
    -
    - {{ getOneCategory(77,'title') }} -
    更多>> -
    -
    +
    + {{ getOneCategory(77,'title') }} +
    更多>> +
    +
      @if (getArticlesBYCate(77,3)->isNotEmpty()) @foreach (getArticlesBYCate(77,3) as $info) @@ -271,7 +284,8 @@ @endif
    + data-href="{{ getVideoByCate(29,'show_link') }}" + style="-webkit-line-clamp: 2;"> {{ getVideoByCate(29,'title') }}