Is it possoble to get the latest post from each tag only


#1

I’m trying to build a custom homepage with a layout based on internal tags. Ideally, it should display the latest article from each tag in its assigned place. This works well with just hardcoding foreaches. The thing is that I also want to wrap everything in a get in order to reuse articles that are no longer that are the most recent in the tag. So far, my code looks like this:

{{#get "posts" limit="4" filter="tags:[hash-headline,hash-quote,hash-figure,hash-aside]" include="tags,authors"}}

<main>
	{{#get "posts" limit="1" filter="tags:[hash-headline]" include="tags,authors" as |headline|}}
		{{#foreach headline}}
		[do_stuff]
		{{/foreach}}
	{{/get}}

	{{#get "posts" limit="1" filter="tags:[hash-quote]" include="tags,authors" as |quote|}}
		{{#foreach quote}}
		[do_stuff]
		{{/foreach}}
	{{/get}}

	{{#get "posts" limit="1" filter="tags:[hash-figure]" include="tags,authors" as |figure|}}
		{{#foreach figure}}
		[do_stuff]
		{{/foreach}}
	{{/get}}

	{{#get "posts" limit="1" filter="tags:[hash-aside]" include="tags,authors" as |aside|}}
		{{#foreach aside}}
		[do_stuff]
		{{/foreach}}
	{{/get}}
</main>

<aside>
	{{#get "posts" limit="3" filter="featured:false+id:-[{{posts[*].id}}]" include="tags,authors"}}
		{{#foreach posts}}
		[do_stuff]
		{{/foreach}}
	{{/get}}
</aside>

<aside>
	{{#get "posts" limit="3" filter="featured:true+id:-[{{posts[*].id}}]" include="tags,authors"}}
		{{#foreach posts}}
		[do_stuff]
		{{/foreach}}
	{{/get}}
</aside>

{{/get}}

The intended outcome is that as soon as there’s a new post with hash-, in <main>, the previous one would fall back to either of the <aside>s. However, this can only work properly when the internal tags are updated sequentially; as soon as they “skip line”, the previous post with the same hashtag goes directly out of view. Playing with the limit value may help sometimes, but it’s mostly hit-and-miss.

So I suppose that I would need to scope them more narrowly in the wrapper get, with just the latest article having each of the tags. How/would this be possible?


#2

I hope it’s possible as well. I have a client you wants to do this as well.

See this screenshot : https://jmp.sh/A9T8yhr

Cheers!


closed #3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.