优化seo文章标题显示;

This commit is contained in:
2022-05-26 10:41:29 +08:00
parent 1d9377da5f
commit 2a71b4e65d
2 changed files with 18 additions and 5 deletions

View File

@@ -28,6 +28,8 @@ class Index extends Common
return $content;
}
$page_title = '全部文章';
//
$sub_category = [];
$current_category = [];
@@ -35,8 +37,11 @@ class Index extends Common
$category_id = $this->request->param('category_id');
if (!empty($category_id)) {
$sub_category = Category::where('pid', $category_id)->where('type', 3)->order('sort asc')->select();
$current_category = Category::find($category_id);
$page_title = $current_category->title;
$sub_category = Category::where('pid', $category_id)->where('type', 3)->order('sort asc')->select();
if (empty($this->request->param('sub_category_id'))) {
$categorys = [$category_id];
@@ -46,6 +51,7 @@ class Index extends Common
$model_post = Post::hasWhere('categorys', $categorys_where)->where('status', 1)->order('id desc');
} else {
$page_title .= "|{$sub_category->title}";
$model_post = Post::hasWhere('categorys', ['category_id' => $this->request->param('sub_category_id')])->where('status', 1)->order('id desc');
}
} else {
@@ -58,16 +64,22 @@ class Index extends Common
$keywords = $this->request->param('keywords');
if (!empty($keywords)) {
$model_post->whereLike('title|desc', "%$keywords%");
$model_post->whereLike('title|desc|content', "%$keywords%");
$page_title .= "|{$keywords}";
}
$page = $this->request->param('page', 1);
$page_title .= "|第{$page}";
$list_post = $model_post->paginate([
'url' => 'Index/index',
'query' => [
'category_id' => $this->request->param('category_id'),
'sub_category_id' => $this->request->param('sub_category_id'),
'page' => $this->request->param('page'),
'page' => $page,
'keywords' => $keywords
],
'list_rows' => 10
]);
@@ -76,6 +88,7 @@ class Index extends Common
View::assign('sub_category', $sub_category);
View::assign('list_post', $list_post);
View::assign('page_title', $page_title);
$content = View::fetch();