[Blade Templates] How to show associated blog content from a tag? #4775
-
Using this Statamic Blade, I'm trying to show blog entries that're linked to a tag. From the Statamic youtube tutorial, it uses However, I'm using blade. Using From looking at the dump, Although I could do a full on query, for each tag, get all the blog entries from the collection and only show ones with the current tag. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Use the @collection('pages', ['title:is' => 'My Title', 'author:is' => 'Erin', 'limit' => 3, 'sort' => 'title:desc'])\
@if($entry['no_results'])
<p>There are no results</p>
@else
{{ $entry['title'] }}
@endif
@endcollection |
Beta Was this translation helpful? Give feedback.
-
Hmm, I wanted to avoid doing a collection query when I'm already in the blog/tags/show.blade.php page and use
^^ Just adding the correct query for Statamic Blade Plugin here incase someone else needs to do the same. Edit Real AnswerI figured out a better solution. Since it's an EntryQueryBuilder, we can do all the same commmands as Content Queries. Which means we can run
Thus there's no need to requery for ALL the blog entries, this would just get the blog entries linked to that tag. |
Beta Was this translation helpful? Give feedback.
Hmm, I wanted to avoid doing a collection query when I'm already in the blog/tags/show.blade.php page and use
entries
like the statamic video did. Since entries does exist there and it shows the correct count for all associated values with that said tag.^^ Just adding the correct query for Statamic Blade Plugin here incase someone else needs to do the same.
Edit Real Answer
I figured out a better solution. Since it's an EntryQueryBuilder, we can do all the same commmands as Content Queries. Which means we can run
entries->get()
to get all the associated blog articles. ie