I would like to count blogpost and display its post number based on a stucture field entry.
For example:
I have a post that belongs to structure field A and a post that belongs to structute field N and I would like to have two separate counters.
Somehow I think (based on my research), the best way to go, is to create a group A and a group N and then count the post in those groups.
But I can’t figure out how to do this.
Would be helpful to have your blueprint with the structure field…
The basic procedure would be to map a value to each structure item:
Assuming a structure field like this:
articles:
type: structure
fields:
category:
type: text # This would be the field with A, N etc.
pages:
type: pages
max: 1
query: site.find('notes').children.listed
Thank you a lot for your help.
Maybe I should give a littel more context.
I tried to implement your solution but as far as I understand, this gives each category a fixed number.
A1, B2, C3… maybe I did it wrong
(Sorry if I repeat myself)
What I would like to do, is have a structure item of Category A and one of Category N and so on.
And then I would like to assign lets say 5 posts (or subpages) to A and count how many A posts I have and output each number like so: A1, A2, A3, A4, A5
My blueprint right now looks like this:
postTypes:
type: structure
label: Post categories
help: Add new categories and specify abbreviation
fields:
postCategory:
label: Category
type: text
abbreviation:
label: Abbreviation
type: text
And here my template where the Post-Number is missing:
I have a page named Actueel and there I define my structure fields along with a subpage named 2020. 2020 has also children (blogposts) and for each of those children you can choose one of the different categories (A, N or B and so on) in the structure field.
Am I overthinking things?
I know it would probably be easier to just have pages named A, B, C and then create subpages.
Ah, then the structure field is only for defining the possible categories, but the categories itself are assigned to each blog post via a select field, right? so the structure field is not relevant for what you want to achieve at all.
But the general procedure would be the same, only we don’t use a structure field as basis for the mapping but the posts.
Unfortunately this still doesn’t count the posts of each individual category but instead counts all posts in all categories. (Which is still more, than I could achieve )
No, that doesn’t matter because we filter by value stored in the post, as I said above, the structure field is completely irrelevant for the output here as its only purpose is to define your categories.
But I wonder why your output is the wrong way round, anyway, as if you change the order again. Could you please post the final code or send me the project.