调整页面
This commit is contained in:
@@ -20,19 +20,20 @@ function getOneCategory($categoryId, $return = '')
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 获取文章分类详情
|
* Notes: 获取文章分类详情
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2020/9/10 13:21
|
* @Date : 2020/9/10 13:21
|
||||||
* @param $categoryId
|
* @param $categoryId
|
||||||
* @param string $result
|
* @param string $result
|
||||||
* @return \App\Models\Article
|
* @return \App\Models\Article
|
||||||
*/
|
*/
|
||||||
function getOneArticleBYCate($categoryId, $result = '')
|
function getOneArticleBYCate($categoryId, $result = '')
|
||||||
{
|
{
|
||||||
$info = Article::where('status', 1)
|
$info = Article::where('status', 1)
|
||||||
->ByCategory($categoryId)
|
->ByCategory($categoryId)
|
||||||
->latest('sort')
|
->latest('sort')
|
||||||
->latest()
|
->latest()
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($info) {
|
if ($info) {
|
||||||
if ($result) {
|
if ($result) {
|
||||||
@@ -49,6 +50,7 @@ function getOneArticleBYCate($categoryId, $result = '')
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 获取分类下的文章
|
* Notes: 获取分类下的文章
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2020/9/10 10:05
|
* @Date : 2020/9/10 10:05
|
||||||
* @param $categoryId
|
* @param $categoryId
|
||||||
@@ -59,33 +61,58 @@ function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
|
|||||||
{
|
{
|
||||||
if ($mark == 'one') {
|
if ($mark == 'one') {
|
||||||
$articles = Article::where('status', 1)
|
$articles = Article::where('status', 1)
|
||||||
->ByCategory($categoryId)
|
->ByCategory($categoryId)
|
||||||
->latest('sort')
|
->latest('sort')
|
||||||
->latest()
|
->latest()
|
||||||
->take($take)
|
->take($take)
|
||||||
->get();
|
->get();
|
||||||
} else {
|
} else {
|
||||||
$cate = Category::find($categoryId);
|
$cate = Category::find($categoryId);
|
||||||
$ids = $cate->getAllChildrenId();
|
$ids = $cate->getAllChildrenId();
|
||||||
|
|
||||||
$articles = Article::where('status', 1)
|
$articles = Article::where('status', 1)
|
||||||
->ByCategory($ids)
|
->ByCategory($ids)
|
||||||
->latest('sort')
|
->latest('sort')
|
||||||
->latest()
|
->latest()
|
||||||
->take($take)
|
->take($take)
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $articles;
|
return $articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 获取带图片的文章
|
||||||
|
*
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date: 2022/3/4 16:52
|
||||||
|
* @param $categoryId
|
||||||
|
* @param $take
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function getArticlesAndCoverBYCate($categoryId, $take = 8)
|
||||||
|
{
|
||||||
|
$cate = Category::find($categoryId);
|
||||||
|
$ids = $cate->getAllChildrenId();
|
||||||
|
|
||||||
|
return Article::where('status', 1)
|
||||||
|
->ByCategory($ids)
|
||||||
|
->where(function ($query) {
|
||||||
|
$query->whereNotNull('cover')->orWhere('cover', '<>', '');
|
||||||
|
})
|
||||||
|
->latest('sort')
|
||||||
|
->latest()
|
||||||
|
->take($take)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
//获取子分类
|
//获取子分类
|
||||||
function getCateChild($categoryId)
|
function getCateChild($categoryId)
|
||||||
{
|
{
|
||||||
return Category::where('status', 1)
|
return Category::where('status', 1)
|
||||||
->where('parent_id', $categoryId)
|
->where('parent_id', $categoryId)
|
||||||
->orderBy('order', 'asc')
|
->orderBy('order', 'asc')
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取顶级分类
|
//获取顶级分类
|
||||||
@@ -104,9 +131,9 @@ function getTopCate($categoryId)
|
|||||||
function getOneAdvertByCate($categoryId, $result = '')
|
function getOneAdvertByCate($categoryId, $result = '')
|
||||||
{
|
{
|
||||||
$info = Advert::where('category_id', $categoryId)
|
$info = Advert::where('category_id', $categoryId)
|
||||||
->latest('sort')
|
->latest('sort')
|
||||||
->latest()
|
->latest()
|
||||||
->first();
|
->first();
|
||||||
if ($info) {
|
if ($info) {
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $info->{$result};
|
return $info->{$result};
|
||||||
@@ -123,8 +150,8 @@ function getOneAdvertByCate($categoryId, $result = '')
|
|||||||
function getAdvertsByCate($categoryId, $take = 8)
|
function getAdvertsByCate($categoryId, $take = 8)
|
||||||
{
|
{
|
||||||
return Advert::where('category_id', $categoryId)
|
return Advert::where('category_id', $categoryId)
|
||||||
->latest('sort')
|
->latest('sort')
|
||||||
->latest()
|
->latest()
|
||||||
->take($take)->get();
|
->take($take)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Advert;
|
use App\Models\Advert;
|
||||||
|
use App\Models\Article;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
|
||||||
class CategoryController extends Controller
|
class CategoryController extends Controller
|
||||||
@@ -10,20 +11,28 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示分类
|
* 显示分类
|
||||||
|
*
|
||||||
* @param Category $category [description]
|
* @param Category $category [description]
|
||||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View [type] [description]
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View [type] [description]
|
||||||
*/
|
*/
|
||||||
public function index(Category $category)
|
public function index(Category $category)
|
||||||
{
|
{
|
||||||
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
|
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
|
||||||
return redirect("articles/" . $category->article_id);
|
return redirect("articles/".$category->article_id);
|
||||||
} else {
|
} else {
|
||||||
$articles = $category->relations(Category::TYPE_ARTICLE)
|
// $articles = $category->relations(Category::TYPE_ARTICLE)
|
||||||
->where('status', 1)
|
// ->where('status', 1)
|
||||||
->latest('sort')
|
// ->latest('sort')
|
||||||
->latest()
|
// ->latest()
|
||||||
->paginate();
|
// ->paginate();
|
||||||
$parent = $category;
|
|
||||||
|
$articles = Article::ByCategory($category->getAllChildrenId())
|
||||||
|
->where('status', 1)
|
||||||
|
->latest()
|
||||||
|
->latest('created_at')
|
||||||
|
->paginate();
|
||||||
|
|
||||||
|
$parent = $category;
|
||||||
|
|
||||||
if ($category->childrens->isEmpty() && $category->parent) {
|
if ($category->childrens->isEmpty() && $category->parent) {
|
||||||
$parent = $category->parent;
|
$parent = $category->parent;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -71,6 +71,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- end 第一模板 -->
|
<!-- end 第一模板 -->
|
||||||
|
|
||||||
|
<!-- 通图 轮播图 start -->
|
||||||
|
<div class="tong_banner">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="swiper-container tong_banner1 contant">
|
||||||
|
<div class="swiper-wrapper">
|
||||||
|
<div class=" idx_banner swiper-slide">
|
||||||
|
<img src="/assets/index/images/banner_1.png" alt="节约能源图片">
|
||||||
|
</div>
|
||||||
|
<div class=" idx_banner swiper-slide">
|
||||||
|
<img src="/assets/index/images/banner_2.png" alt="节约能源图片">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="swiper-pagination swiper-pagination-dian"></div>
|
||||||
|
</div>
|
||||||
|
<!-- 通图 轮播图 end -->
|
||||||
|
|
||||||
|
|
||||||
<!-- 第二模板 -->
|
<!-- 第二模板 -->
|
||||||
@if (getArticlesBYCate(24,4)->isNotEmpty())
|
@if (getArticlesBYCate(24,4)->isNotEmpty())
|
||||||
|
|
||||||
@@ -85,7 +104,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul class="newTwo-list">
|
<ul class="newTwo-list">
|
||||||
@foreach (getArticlesBYCate(24,4) as $article)
|
@foreach (getArticlesAndCoverBYCate(24,6) as $article)
|
||||||
<li data-href="{{ $article->link }}">
|
<li data-href="{{ $article->link }}">
|
||||||
<div class="ce-img newTwo-list-img">
|
<div class="ce-img newTwo-list-img">
|
||||||
<span style="background-image: url({{ $article->cover_path }});"></span>
|
<span style="background-image: url({{ $article->cover_path }});"></span>
|
||||||
@@ -103,6 +122,13 @@
|
|||||||
|
|
||||||
<!-- end 第二模板 -->
|
<!-- end 第二模板 -->
|
||||||
|
|
||||||
|
<!-- 通图 start -->
|
||||||
|
<div class="contant banner_3">
|
||||||
|
<img src="/assets/index/images/banner_3.png" alt="节约能源图片">
|
||||||
|
</div>
|
||||||
|
<!-- 通图 end -->
|
||||||
|
|
||||||
|
|
||||||
<!-- 第三模板 -->
|
<!-- 第三模板 -->
|
||||||
<div class="idxThree">
|
<div class="idxThree">
|
||||||
<div class="contant">
|
<div class="contant">
|
||||||
@@ -241,12 +267,15 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('script')
|
@push('script')
|
||||||
|
<!-- Swiper JS -->
|
||||||
<script>
|
<script>
|
||||||
// banner轮播
|
// banner轮播
|
||||||
var banner = new Swiper('.idxBanner', {
|
var banner = new Swiper('.idxBanner', {
|
||||||
pagination: '.swiper-pagination-white'
|
pagination: '.swiper-pagination-white'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var tong_banner = new Swiper('.tong_banner', {})
|
||||||
|
|
||||||
// 轮播
|
// 轮播
|
||||||
var idxFour = new Swiper('.idxFour-container', {
|
var idxFour = new Swiper('.idxFour-container', {
|
||||||
nextButton: '.swiper-button-next',
|
nextButton: '.swiper-button-next',
|
||||||
@@ -255,5 +284,14 @@
|
|||||||
paginationClickable: true,
|
paginationClickable: true,
|
||||||
spaceBetween: 30,
|
spaceBetween: 30,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var tong_banner1 = new Swiper('.tong_banner1', {
|
||||||
|
pagination: '.swiper-pagination',
|
||||||
|
paginationClickable: true,
|
||||||
|
loop: true,
|
||||||
|
autoplay: 4000,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@endpush
|
@endpush
|
||||||
Reference in New Issue
Block a user