Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hello,

I am trying to show the top 5 most written about subjects in a page on my blog.
The subject field is a dropdown menu editable, and I can select which subject is linked to the article I'm creating.

What I did for now, is a table with all subjects, with the "k_total_records" data next to it. So I can see the information for each subjects.
I used that type of code for each subjects (nomsujet being the subject editable name, and 1031 being the value of a subject) :
Code: Select all
<cms:pages masterpage="search.php" limit="1" custom_field='nomsujet=1031'></td><td><cms:show k_total_records/></cms:pages>


I tried doing this :

Code: Select all
<cms:pages masterpage="search.php" limit="5" orderby=k_total_records order="desc"><cms:show nomsujet/> = (<cms:show k_total_records/>)</cms:pages>


I wanted to show change the order so that it goes by how many "total records" there is for each subjects, but I get that it cannot work since I'm not specifying any subjects, so it will show the total number of entries in the search.php page.

Any ideas how I can do this?

Thanks a lot!
If you had `nomsujet` as a relation editable with has='one' (by default looks like a dropdown -- i.e. without 'advanced_gui' set), then listing top5 would be easy. Solution in case of such relation should be based on 'aggregate_by' parameter of cms:pages with orderby='k_rel_count'.

If the change from simple dropdown to relation is too costly, then it will be either dancing with counters or arrays or, better, a custom SQL query (fairly straightforward).
Say `Please!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]..... Active topics [Forum posts from previous 7 days].... helpcouch@mail.ru [My email for friends]
Thanks,

Never heard of the "aggregate_by" parameter before.
So if the field on my "search.php" would be a relation region, with the "has=one" parameter, I should be able to list how many times each items in the relation field is saved in that clonable template?

I tried :
Code: Select all
<cms:pages masterpage='search.php' aggregate_by='search.php::listedesnoms' custom_field='k_rel_count' orderby='k_rel_count'  >
<cms:related_pages 'listedesnoms'><cms:show k_page_title/> (<cms:show k_rel_count />)</cms:related_pages>
</cms:pages>


But it's displaying all items in that relation, and the number between paratheses is the number of time that item exists, so it's all filled with "(1)" next to these names.

I'm using the "search.php" page twice, because that page has all the entries in the backend, and I'm using the front-end part of the page to display some stats. I'm kind of lost here.

Thanks!
Never heard of the "aggregate_by" parameter before.

It's never late to learn something new :) Sometimes I also get stuck with aggregation (but fortunately it was never a full stop) due to various complications that I often wish to solve in a single line of code. I always find the parameter return_sql='1' to be extremely helpful in revealing the mechanism that performs the aggregation and counting. Sometimes it is easy to copy the SQL, do some tweaks in it manually and fire a cms:query, which would do the job just like cms:pages does.
Say `Please!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]..... Active topics [Forum posts from previous 7 days].... helpcouch@mail.ru [My email for friends]
4 posts Page 1 of 1

Who is online

In total there are 8 users online :: 1 registered, 0 hidden and 7 guests
(based on users active over the past 5 minutes)

Users browsing this forum: Google [Bot] and 7 guests