I've found the following code in Posts.php - I think I essentially need to duplicate this and turn it into a public function limiting the category to a sepcific ID. Although that seems overkill? Can I query the current function on the front end?
Here's the posts.php code:
protected function listPosts()
{
$category = $this->category ? $this->category->id : null;
/*
* List all the posts, eager load their categories
*/
$isPublished = !$this->checkEditor();
$posts = BlogPost::with('categories')->listFrontEnd([
'page' => $this->property('pageNumber'),
'sort' => $this->property('sortOrder'),
'perPage' => $this->property('postsPerPage'),
'search' => trim(input('search')),
'category' => $category,
'published' => $isPublished,
'exceptPost' => $this->property('exceptPost'),
]);
/*
* Add a "url" helper attribute for linking to each post and category
*/
$posts->each(function($post) {
$post->setUrl($this->postPage, $this->controller);
$post->categories->each(function($category) {
$category->setUrl($this->categoryPage, $this->controller);
});
});
return $posts;
}
on the front end is this:
{% for post in posts %}
<li>
<h3><a href="{{ post.url }}">{{ post.title }}</a></h3>
</li>
{% else %}
<li class="no-data">{{ noPostsMessage }}</li>
{% endfor %}
Could someone point me in the right direction?
Cheers,