simply icon indicating copy to clipboard operation
simply copied to clipboard

[PREV-NEXT] Prev-next article only for those with same primary tag

Open StanGirard opened this issue 4 years ago • 9 comments

Hello,

I've implemented this on my blog. The prev and next article only give you the articles with the same tags. Here is the code that I added on all the post templates

<div class="prev-next">
            {{#get "posts" filter="tags:{{primary_tag.slug}}+id:>{{id}}" limit="1"order="id asc"}}
                {{#foreach posts}}
                    {{> "story/story-previous-next" storyTitle=(t "Next article") class="u-marginBottom30"}}
                {{/foreach}}
            {{/get}}
            {{#get "posts" filter="tags:{{primary_tag.slug}}+id:<{{id}}" limit="1" order="id desc"}}
                {{#foreach posts}}
                    {{> "story/story-previous-next" storyTitle=(t "Previous article") class=""}}
                {{/foreach}}
            {{/get}}
        </div>

StanGirard avatar Mar 27 '20 10:03 StanGirard

Hello :nerd_face:

How are you?

What you're proposing is interesting. But here's a problem, using the helper #get causes a little bit of slowness on the server.

That's why I'm thinking of not using the helper #get

But in ghost. documentation you can do the same thing you propose, you don't need to use the helper #get

https://ghost.org/docs/api/v3/handlebars-themes/helpers/prev_next_post/

{{#post}}
	{{#prev_post in="primary_tag"}}
		<a href="{{url}}">{{title}}</a>
	{{/prev_post}}

	{{#next_post in="primary_tag"}}
		<a href="{{url}}">{{title}}</a>
	{{/next_post}}
{{/post}}

godofredoninja avatar Mar 27 '20 16:03 godofredoninja

God damn it I wish I had found it earlier ! Took me a while to implement it :D

I'll modify the pull request to implement these changes

How bad is get ? It's only slow at compile time no ?

StanGirard avatar Mar 27 '20 16:03 StanGirard

Pull Request done. What could be interesting is depending on the kind of post you could either use this new template or the old one depending of an internal tag.

We could read the internal tag such as #series. If #series is present then we show the new next-prev. But if not present we could show the old one.

StanGirard avatar Mar 27 '20 16:03 StanGirard

:thinking:

I think that's it.

I don't really provide it.

Experiment and tell me.

If you find something better than this solution... let me know


{{#prev_post in="primary_tag"}}
	<a href="{{url}}">{{title}}</a>
{{else}}
	{{#get "posts" filter="tags:{{primary_tag.slug}}+id:>{{id}}" limit="1"order="id asc"}}
		<!-- -->
	{{/get}}
{{/prev_post}}

{{#next_post in="primary_tag"}}
	<a href="{{url}}">{{title}}</a>
{{else}}
	{{#get "posts" filter="tags:{{primary_tag.slug}}+id:>{{id}}" limit="1"order="id asc"}}
		<!--  -->
	{{/get}}
{{/next_post}}

godofredoninja avatar Mar 27 '20 18:03 godofredoninja

What I ended up doing is

{{#has tag="#series"}}
                {{#next_post in="primary_tag"}}
                        {{> "story/story-previous-next" storyTitle=(t "Next article") class="u-marginBottom30"}}
                {{/next_post}}
                {{#prev_post in="primary_tag"}}
                        {{> "story/story-previous-next" storyTitle=(t "Previous article") class=""}}
                {{/prev_post}}
            {{else}}
                {{#next_post}}
                        {{> "story/story-previous-next" storyTitle=(t "Next article") class="u-marginBottom30"}}
                {{/next_post}}
                {{#prev_post}}
                        {{> "story/story-previous-next" storyTitle=(t "Previous article") class=""}}
                {{/prev_post}}
            {{/has}}

If the post has an internal tag #series then it only shows in the next-prev the articles with the same primary tag

StanGirard avatar Mar 27 '20 23:03 StanGirard

What is nice about it is that it doesn't change the default behavior. And for those who want this feature they only have to put #series as internal tag.

StanGirard avatar Mar 30 '20 14:03 StanGirard

Your contribution is great.

And I am very happy about that ..

At the moment I am working on simply. The new simply theme will be with subscriber support, also my kusi Doc theme will be included in Simply.

If you have any ideas to improve the design or performance aspect, please do not hesitate to tell me.

When everything updates the idea you have, I will publish it in a more beautiful and understandable documentation.

godofredoninja avatar Apr 22 '20 15:04 godofredoninja

Your contribution is great.

And I am very happy about that ..

At the moment I am working on simply. The new simply theme will be with subscriber support, also my kusi Doc theme will be included in Simply.

If you have any ideas to improve the design or performance aspect, please do not hesitate to tell me.

When everything updates the idea you have, I will publish it in a more beautiful and understandable documentation.

Author are you alive?

uPagge avatar Sep 20 '21 16:09 uPagge

Hello @uPagge

Yes.

They revived me with the 🐉 dragon balls 🎈

godofredoninja avatar Dec 30 '21 23:12 godofredoninja