I need 3 range queries for my sidebar

Really struggling with the template functions for taxonomies. I need 3 sidebar range queries for my site’s side bar.

If home page

So far, I’m just showing the first 4 oldest posts in reverse. But I would prefer a range query that only picks posts that aren’t already displayed in the main range queries.

{{ range first 4 .Pages.Reverse }}
    <-- HTML -->
{{ end }}

If category page

I’d like to show posts that do not belong in the main category, but I can’t get the “if not in” syntax right show here: How to check for ‘not in’ in if statements?

If single page

I’d like the single page sidebar to show posts from the same cats as the single post. I’m close with this one, but I’m struggling to populate the cats dynamically and as a list.

{{ range .Site.Pages}}
    {{ if in .Params.categories "[mycat1, mycat2]" }}
        <-- HTML -->
    {{ end }}
{{ end }}

Any help would be appreciated.

I see some minor syntax issues with what you have above (e.g. }), but it would really help if you could give the community a link to your source so that we can test locally.

1 Like

Sorry, it’s private.

Sorry bud. Can’t help you much. There are a whole slew of things that might be going wrong for you with this. For example, are you declaring your taxonomies in your config? Are you getting any errors in the console? I’m also not sure what you mean by “picks posts that aren’t already displayed in the main range queries.” The only thing I can think of w/r/t your if not question is:

...
{{ if and (not in .Params.categories "mycat1") (not in .Params.categories "mycat2")}}
{{ end }}
...

Good luck!

1 Like

I suggest you make a smaller project that is public, and include the templates you are working with. Not only will you get a repo to share, you will likely progress on the issue when putting it together. :slight_smile:

3 Likes

OK, understood. Thanks for the advice. Will make better examples available in future.

1 Like