Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
I've been awake for a while I can't figure out how best to phrase my title.

So for example I have services.php which has "baking, cooking, frying, grilling" as individual pages.
Then I have a blog that has many many blog posts, each post having a "has='one' relation" to one of the services.
So, blog one can be related to baking, blog two related to frying, blog three related to baking again.

When I loop through the blog pages (<cms:pages 'blog.php'>) I wil end up with a blog-title and the service it's related to for each blog entry. Lets say the following example is what I get:

    Title: How to fry fish, Service: frying
    Title: How to bake fish, Service: baking
    Title: How to fry brisket, Service: frying
    Title: How to bake brisket, Service: baking
    Title: How to fry okra, Service: frying

I'm looking for a way to cache the services from this loop so I only end up with one "frying" value of 3 and one "baking" value of 2,

Sorry for the lengthy explanation
---
You live many times, but only ever remember your lives.length - 1
---
Image
cholasimmons wrote: I'm looking for a way to cache the services from this loop so I only end up with one "frying" value of 3 and one "baking" value of 2,

Sorry for the lengthy explanation

Could you explain a little bit more the expected result? :)
If duplicates are filtered out, then listing will only show 4 "unique-service" blog posts - same as listing services and showing 1 single related blog post for each.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Some sort of if statement combined with couch set directives would work for this, I'm just looking for an inbuilt solution if one does exist.

Let's say a loop results in "baking, baking, frying, baking and frying".
That's 3 baking, and 2 frying.

I only want baking to appear once (with a value of 3 since there were 3 entries with baking,
and frying appears once with a value of 2
---
You live many times, but only ever remember your lives.length - 1
---
Image
How about aggregate_by clause (Aggregate queries (involving count): viewtopic.php?f=5&t=8581 ) -

we can query the reverse-related template by explicitly specifying the name of the containing template with the relation field's name e.g. the following will list all courses with the number of students taking them -

Code: Select all
    <cms:pages masterpage='courses.php' aggregate_by='students.php::take' custom_field="k_rel_count>1" orderby='k_rel_count' >
        <a href="<cms:show k_page_link />"><h3><cms:show k_page_title /> (<cms:show k_rel_count />)</h3></a>
    </cms:pages>
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
4 posts Page 1 of 1