Merge pull request #361 from lbryio/fix/290_support_for_blog_tags

Add category filter for news post
This commit is contained in:
Jeremy Kauffman 2018-02-05 18:23:20 -05:00 committed by GitHub
commit fda77f6204
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -125,6 +125,7 @@ class Controller
$router->any('/yt2', 'AcquisitionActions::executeYT2');
$router->get('/verify/{token}', 'AcquisitionActions::executeVerify');
$router->get('/news/category/{category}', 'ContentActions::executePostCategoryFilter');
$router->post('/set-culture', 'i18nActions::setCulture');

View file

@ -364,4 +364,25 @@ class ContentActions extends Actions
'posts' => array_slice(Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), 0, $count)
];
}
public static function executePostCategoryFilter(string $category)
{
Response::enableHttpCache();
$filter_post = [];
$posts = array_filter(
Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC),
function(Post $post) use ($category) {
return (($post->getCategory() === $category) && (!$post->getDate() || $post->getDate()->format('U') <= date('U')));
});
return ['content/news', [
'posts' => $posts,
View::LAYOUT_PARAMS => [
'showRssLink' => true
]
]];
}
}