Skip to content

Commit b5030ae

Browse files
author
fengr06
committed
博文详情增加锚点
1 parent 961632b commit b5030ae

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

app/Http/Controllers/ArticleController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public function show(Request $request, $id)
8282
$article->created_at_date = $article->created_at->toDateString();
8383
$article->updated_at_date = $article->updated_at->toDateString();
8484
$comments = $article->comments()->where('parent_id', 0)->orderBy('created_at', 'desc')->get();
85+
$field = 'id, title';
86+
$preArticle = Article::select(DB::RAW("$field"))->where('is_hidden', 0)->where('id', '<', $id)->orderBy('is_top', 'desc')->orderBy('created_at', 'desc')->orderBy('id', 'desc')->first();
87+
$bacArticle = Article::select(DB::RAW("$field"))->where('is_hidden', 0)->where('id', '>', $id)->orderBy('is_top', 'desc')->orderBy('created_at', 'desc')->orderBy('id', 'asc')->first();
8588
$count = $article->comments()->count();
8689
$article->words = mb_strlen(strip_tags($article->content_html), 'UTF8');
8790
$article->read = ceil($article->words / 1000);
@@ -149,7 +152,7 @@ public function show(Request $request, $id)
149152

150153
$article->content_html = $content;
151154
$tags = $article->tags;
152-
return view(env('BLOG_THEME') . '.articles.show', compact('article', 'comments', 'input', 'count', 'outline', 'tags', 'articleCount', 'catesCount', 'tagsCount'));
155+
return view(env('BLOG_THEME') . '.articles.show', compact('article', 'comments', 'input', 'count', 'outline', 'tags', 'articleCount', 'catesCount', 'tagsCount', 'preArticle', 'bacArticle'));
153156
}
154157

155158

resources/views/next/articles/show.blade.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,23 @@ class="fa fa-paw"></i>感谢您的阅读-------------
118118
@endforeach
119119
@endif
120120
</div>
121-
{{--<div class="post-nav">--}}
122-
{{--<div class="post-nav-next post-nav-item">--}}
123-
{{--<a href="/2018/04/24/protobuf嵌套结构定义的赋值问题/" rel="next"--}}
124-
{{--title="protobuf嵌套结构定义的赋值问题">--}}
125-
{{--<i class="fa fa-chevron-left"></i> protobuf嵌套结构定义的赋值问题--}}
126-
{{--</a>--}}
127-
{{--</div>--}}
128-
{{--<span class="post-nav-divider"></span>--}}
129-
{{--<div class="post-nav-prev post-nav-item">--}}
130-
{{--<a href="/2018/05/22/秒杀系统的一些思考/" rel="prev" title="秒杀系统的一些思考">--}}
131-
{{--秒杀系统的一些思考 <i class="fa fa-chevron-right"></i>--}}
132-
{{--</a>--}}
133-
{{--</div>--}}
134-
{{--</div>--}}
121+
<div class="post-nav">
122+
@if($preArticle)
123+
<div class="post-nav-next post-nav-item">
124+
<a href="{{ route('articles.show', $preArticle->id) }}" rel="next" title="{{$preArticle->title}}">
125+
<i class="fa fa-chevron-left"></i>{{$preArticle->title}}
126+
</a>
127+
</div>
128+
@endif
129+
<span class="post-nav-divider"></span>
130+
@if($bacArticle)
131+
<div class="post-nav-prev post-nav-item">
132+
<a href="{{ route('articles.show', $bacArticle->id) }}" rel="prev" title="{{$bacArticle->title}}">
133+
{{$bacArticle->title}} <i class="fa fa-chevron-right"></i>
134+
</a>
135+
</div>
136+
@endif
137+
</div>
135138
</footer>
136139
</div>
137140
</article>

0 commit comments

Comments
 (0)