I am doing this to get posts form specific section, but from other types are also showing. I have also tried {{ $posts := where .Site.RegularPages "Section" "posts" }}, but it’s not working. please help and tell me where I’m mistaken!
Page Type:
The content type is defined by the type field in front matter, or inferred from the top-level directory name if the type field in front matter is not defined.
Page Kind
A page kind is a classification of pages, one of home , page , section , taxonomy , or term
So it depends of how YOU specify the type ‘posts’ of pages.
by front matter on every page or cascade it down
toplevel directory
a mixture of both
.Site.RegularPages returns only pages of Kind ‘page’,
so: Where .Site.RegularPages "Section" "posts" will return all normal pages below the toplevel folder content/pages. Should be the same as Where .Site.RegularPages "Type" posts" unless you have different type of pages using front matter values below /content/posts
Keep in mind, that with front matter type = "post" is different from type = "posts"
I could think of a double paginate call on your list page.
Please note that the results of pagination are cached. Once you have invoked either the Paginator or Paginate method, the paginated collection is immutable. Additional invocations of these methods will have no effect.
content/categories (term)
content/post (type will be post - not defined in frontmatter)
content/page (type will be page)
content/_index.md (home)
content/normal-page.md (a page)
content/search.md (layout: search)
I want to use the top-level folder name for that. because I don’t want to add type: post or type: posts, I want to use the folder name as type.
In this case the {{ $posts := where .Site.RegularPages "Type" "post" }} should work. but it’s giving me all of those inside content. like normal-page, search and each post in post content folder
If I don’t paginate then it returns all content files from post folder
First load you paginator collection with the content you need to paginate on : {{ $paginator := .Paginate (where .Data.Pages "Section" "posts" ) 21 }}
or in your case {{ $paginator := .Paginate (where .Site.RegularPages "Type" "posts") 21 }}
( 21 is the number of elements on each paginated page, it can be any int value. )
Then you can iterate over the $paginator object as you would with anything else.
For instance : {{ range $paginator.Pages }}
Finally you can call the pagination itself, it will take advantage of the $paginator collection
Not if you need to access the Paginator early in the template, before you’ve defined the page collection to be paginated, which is what this topic is about.