Refactor
This commit is contained in:
parent
fb4ff11945
commit
88bf48dc6f
2 changed files with 24 additions and 2 deletions
|
@ -42,6 +42,27 @@ class Blog
|
|||
throw new \Exception('No post found with the slug "' . $slug . '".');
|
||||
}
|
||||
|
||||
public static function getPreviousCurrentNextPostBySlug(string $slug): array
|
||||
{
|
||||
$posts = self::get(self::ENDPOINT_POSTS);
|
||||
|
||||
for ($i = 0; $i < count($posts); $i++) {
|
||||
$previous = $posts[$i - 1] ?? null;
|
||||
$current = $posts[$i] ?? null;
|
||||
$next = $psots[$i + 1] ?? null;
|
||||
|
||||
if ($slug === $current->slug) {
|
||||
return array(
|
||||
'previous' => $previous,
|
||||
'current' => $current,
|
||||
'next' => $next,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw new \Exception('No post found with the slug "' . $slug . '".');
|
||||
}
|
||||
|
||||
public static function getPosts(): array
|
||||
{
|
||||
$posts = self::get(self::ENDPOINT_POSTS);
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
namespace wishthis;
|
||||
|
||||
$postSlug = $_SESSION['_GET']['slug'];
|
||||
$post = Blog::getPostBySlug($postSlug);
|
||||
$posts = Blog::getPreviousCurrentNextPostBySlug($postSlug);
|
||||
$post = $posts['current'];
|
||||
$postMediaHTML = isset($post->featured_media) ? Blog::getMediaHTML($post->featured_media) : '';
|
||||
$postMedia = isset($post->featured_media) ? Blog::getMedia($post->featured_media) : new \stdClss();
|
||||
|
||||
|
@ -47,8 +48,8 @@ $page->navigation();
|
|||
</div>
|
||||
|
||||
<div class="ui two columns grid">
|
||||
<div class="column">
|
||||
|
||||
<div class="column">
|
||||
<a href="#top" class="ui fluid labeled icon button">
|
||||
<i class="arrow up icon"></i>
|
||||
<?= __('Top') ?>
|
||||
|
|
Loading…
Reference in a new issue