Problems, need help? Have a tip or advice? Post it here.
18 posts Page 2 of 2
This will output something like:
5, 5, 4, 3, 2, 5, 4, 3, 3, 2
Desired list:
5, 5, 5, 4, 4, 3, 3, 3, 2, 2
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
Hi,

Well seems to be a hard nut to crack ... I suppose it comes down to the <cms:query> tag like in this post :
viewtopic.php?p=13982#p13982

or is this also looping separate trough the boys and girls templates ?
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Hi,

As we know, the cms:pages tag works with only a single template
We'll need to use <cms:query> for anything involving multiple templates. In this case, probably custom fields are also involved (e.g. perhaps the 'grade' field is defined in multiple templates) which will make the query more complex.

Can be done, I think, but will need some work to formulate the right SQL query.

@trendoman, could you please post the exact definitions of regions in all the involved templates?
Can't promise but let me see if we can find a way out.
I'm still wondering why this is so hard to accomplish ....

Can someone tell me if the following idea could work ?

Code: Select all
<cms:php>

$gradelist = array(

<cms:templates>
    <cms:if (k_template_name eq 'boys.php') && (k_template_name eq 'girls.php')>
      <cms:pages masterpage=k_template_name>
       
       Boys and Girls unsorted

      </cms:pages>
    </cms:if>
</cms:templates> );

sort($gradelist); Boys and Girls sorted

</cms:php>
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
This part will never be executed, because templates are fetched one by one.
Code: Select all
<cms:if (k_template_name eq 'boys.php') && (k_template_name eq 'girls.php')>

It should at least go with || to reflect OR conditional.
Code: Select all
<cms:if (k_template_name eq 'boys.php') || (k_template_name eq 'girls.php')>

Then there is indeed a php-function so sort things out in a multi-dimensional array, preserving each page ID and the corresponding template name. I come back to this in a few days, after I'm done with more urgent work.
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
@Tomarnst, with the 'OR' clause rectified as suggested by @trendoman, this method can certainly work when the number of pages to fetch from each template is not big.

To illustrate the point, suppose each template has 1000+ pages and we wish to display only the top 5 combined from both. Using the PHP way would fetch all 1000+ pages from the first template then another 1000+ pages from the second template, sort them and output the top 5.

With SQL query, MySQL will optimize this procedure immensely and give you only the 5 we want.

Anyway, as I said, for a smaller number this method should do just fine.
@KK thanks

In my case the number of pages are not more then 50 and I need to output all of them so I'm fine with this.
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
KK, thank you for this insight. I learn more and more each day here :D
I will be pursuing the solution with mysql, then.

I clearly see many applications of this.
-report on top-5 users with most rated comments.
-report top-10 products sold in last quarter.
-and so on.
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
18 posts Page 2 of 2