Skip to content

Commit

Permalink
Ignore categories that do not contain published posts
Browse files Browse the repository at this point in the history
Refs #539
  • Loading branch information
daftspunk committed Apr 5, 2021
1 parent 01ffd57 commit 89eefba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function loadPost()
if (!$this->checkEditor()) {
$query->isPublished();
}

$post = $query->first();

/*
Expand Down
10 changes: 9 additions & 1 deletion models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,16 @@ public static function resolveMenuItem($item, $url, $theme)
'items' => []
];

$categories = self::orderBy('name')->get();
$categories = self::with('posts_count')->orderBy('name')->get();
foreach ($categories as $category) {
try {
$postCount = $category->posts_count->first()->count ?? null;
if ($postCount === 0) {
continue;
}
}
catch (\Exception $ex) {}

$categoryItem = [
'title' => $category->name,
'url' => self::getCategoryPageUrl($item->cmsPage, $category, $theme),
Expand Down

0 comments on commit 89eefba

Please sign in to comment.