From 2b6ad4fe1f4475e2520030404266fe21618a6bfe Mon Sep 17 00:00:00 2001 From: zwesy Date: Thu, 26 Nov 2020 10:28:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E5=92=8C=E4=BA=A7=E5=93=81=E5=9F=BA=E6=9C=AC=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Article.php | 46 +++++---------- app/controller/Index.php | 1 - app/model/Category.php | 17 ++++++ app/widget/Crumbs.php | 3 +- public/static/css/style.css | 2 +- view/article/news.html | 106 ++++++++++++++++++++++++++++++++++ view/article/news_detail.html | 2 + view/article/product.html | 2 + view/article/products.html | 3 + view/index/index.html | 2 +- view/public/crumbs.html | 7 +++ 11 files changed, 157 insertions(+), 34 deletions(-) create mode 100644 view/article/news.html create mode 100644 view/article/news_detail.html create mode 100644 view/article/product.html create mode 100644 view/article/products.html create mode 100644 view/public/crumbs.html diff --git a/app/controller/Article.php b/app/controller/Article.php index 6018362..d18d26a 100644 --- a/app/controller/Article.php +++ b/app/controller/Article.php @@ -44,38 +44,24 @@ class Article extends Base $childCategory = Category::getChildrenByParentId($categoryId); $description = $category['description'] ? $category['description'] : $this->system['seo_description']; $this->setSeo($category['title'], $this->system['seo_keywords'], $description); - $this->data['items'] = MArticle::getListPageByCategory($categoryId, $category['number'] ? $category['number'] : 20); + $childList = []; + $defaultList = []; + // 若存在下级子栏目则优先分组显示子栏目内容 + if(!empty($childCategory)) { + foreach ($childCategory as $child) { + $childList[] = [ + 'category' => $child, + 'items' => MArticle::getListPageByCategory($child['id'], $child['number'] ? $child['number'] : 20), + ]; + } + } else { + $defaultList = MArticle::getListPageByCategory($categoryId, $category['number'] ? $category['number'] : 20); + } + $this->data['items'] = $defaultList; + $this->data['childList'] = $childList; $this->data['category'] = $category; $this->data['categoryId'] = $categoryId; + $this->data['childCategory'] = $childCategory; return $this->view($category['template_list'] ?? ''); } - -// //新闻列表 -// public function news($categoryId) -// { -// dump('新闻资讯'); -// dump($categoryId); -// -// } -// -// //新闻详情 -// public function newsDetail($newsId) -// { -// dump('新闻资讯详情'); -// dump($newsId); -// } -// -// // 产品列表 -//// public function product($categoryId) -//// { -//// dump('产品列表'); -//// dump($categoryId); -//// } -// -// // 产品列表 -// public function productDetail($productId) -// { -// dump('产品详情'); -// dump($productId); -// } } \ No newline at end of file diff --git a/app/controller/Index.php b/app/controller/Index.php index d06e110..0b7da8a 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -22,7 +22,6 @@ class Index extends Base $this->data['newsEnterprises'] = Article::getLatestByCategory(Category::$CIdList['news_enterprise'], 4); // 关联行业资讯 $this->data['newsIndustries'] = Article::getLatestByCategory(Category::$CIdList['news_industry'], 4);; - //dump($this->data); return $this->view(); } } \ No newline at end of file diff --git a/app/model/Category.php b/app/model/Category.php index 2bc9f99..c19e194 100644 --- a/app/model/Category.php +++ b/app/model/Category.php @@ -195,4 +195,21 @@ class Category extends Base } return $data; } + + //根据栏目ID获取面包屑列表 + public static function getListForCrumbs($categoryId) + { + $categories = []; + $category = self::getById($categoryId); + if(!empty($category)){ + $categories[] = $category; + if($category['parent_id'] != 0 ){ + $parents = self::getListForCrumbs($category['parent_id']); + if(!empty($parents)){ + $categories = array_merge($categories, $parents); + } + } + } + return $categories; + } } diff --git a/app/widget/Crumbs.php b/app/widget/Crumbs.php index c43fa6a..f035280 100644 --- a/app/widget/Crumbs.php +++ b/app/widget/Crumbs.php @@ -8,8 +8,9 @@ class Crumbs { public function index($categoryId) { + $list = array_reverse(Category::getListForCrumbs($categoryId)); $data = [ - 'crumbs' => Category::getCatesCrumbs($categoryId) + 'crumbs' => $list ]; return View::assign($data)->fetch('public/crumbs'); } diff --git a/public/static/css/style.css b/public/static/css/style.css index 4f409d6..97024f1 100644 --- a/public/static/css/style.css +++ b/public/static/css/style.css @@ -165,7 +165,7 @@ input,select,textarea{outline:medium none; resize: none;} .foot-box .lower-box .ewm img{ width: 134px;} .page-banner{ height: 40.625rem; position: relative; background-position: center; background-size: cover; position: relative; z-index: 2;} -.page-banner .info{ width: 100%; position: absolute; left: 0; bottom: 2.5rem; color: #fff; padding-bottom: ;} +.page-banner .info{ width: 100%; position: absolute; left: 0; bottom: 2.5rem; color: #fff;} .page-banner .info strong{ font-size: 3.125rem; text-shadow: 0 0 5px rgba(0,0,0,0.5);} .page-banner .info p{ font-size: 1.875rem; text-shadow: 0 0 5px rgba(0,0,0,0.5);} .page-banner .info .w-1200{ position: relative;} diff --git a/view/article/news.html b/view/article/news.html new file mode 100644 index 0000000..2e4bda8 --- /dev/null +++ b/view/article/news.html @@ -0,0 +1,106 @@ +{layout name="layout" /} + +
+ {php} + $bgImg = '__IMG__/page_ban1.jpg'; // 默认背景图 + if (isset($category) && !empty(trim($category['src'])) && file_exists('./'.$category['src'])) { + $bgImg = $category.src; + } + {/php} +
+
+
+
+
+ {:widget('crumbs/index', ['categoryId' => $categoryId])} +
+
+
+ + +
+
+
+ {if isset($childList) && count($childList) > 0} + {foreach $childList as $child} +
+
{$child['category']['title'] ?? ''}
+ {if count($child['items']) > 0} + + {/if} + {/foreach} + + {elseif isset($items) && count($items) > 0 /} + + {/if} +
+
+
\ No newline at end of file diff --git a/view/article/news_detail.html b/view/article/news_detail.html new file mode 100644 index 0000000..a49a9eb --- /dev/null +++ b/view/article/news_detail.html @@ -0,0 +1,2 @@ +{layout name="layout" /} +新闻详情 \ No newline at end of file diff --git a/view/article/product.html b/view/article/product.html new file mode 100644 index 0000000..a49a9eb --- /dev/null +++ b/view/article/product.html @@ -0,0 +1,2 @@ +{layout name="layout" /} +新闻详情 \ No newline at end of file diff --git a/view/article/products.html b/view/article/products.html new file mode 100644 index 0000000..f2f57ff --- /dev/null +++ b/view/article/products.html @@ -0,0 +1,3 @@ +{layout name="layout" /} + +新闻列表 \ No newline at end of file diff --git a/view/index/index.html b/view/index/index.html index 8827328..bb772fb 100644 --- a/view/index/index.html +++ b/view/index/index.html @@ -49,7 +49,7 @@
{$blocks['marketing_name']['value'] ?? ''}

{$blocks['marketing_describe']['value'] ?? ''}

- 了解详情+ + 了解详情++
diff --git a/view/public/crumbs.html b/view/public/crumbs.html new file mode 100644 index 0000000..6c2911b --- /dev/null +++ b/view/public/crumbs.html @@ -0,0 +1,7 @@ +
+ + 首页 + {foreach $crumbs as $crumb} + > {$crumb.title} + {/foreach} +
\ No newline at end of file