Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Help with Sorting in Panels UI (Read 1831 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Help with Sorting in Panels UI

I've searched extensively on this issue, and I've found a few things, but I lack the coding ability to put those bits of code together into something that'll work.

I want to be able to sort my Panels UI playlists according to three criteria:
  • In sorting artist names, leading instances of 'The' are ignored
  • Within an artist, albums are sorted by year
  • Compilation albums are grouped together, preferably at the top or bottom

Would anyone mind writing out the code that would make this work?

Thanks in advance.

Help with Sorting in Panels UI

Reply #1
1. Use the CWB Hooks $cwb_removethe command to remove "The" and "A" (the word, not the letter) from the beginning of a string.  For instance $cwb_removethe(%title%) removes "The" or "A" from the beginning of the title if present.  If you just want "The" removed but not "A", you can use $cwb_ltrim from the same component.  Just do: $cwb_ltrim(%title%,The) You can also use it if you want more than just The and A.  In include "An" as well, by doing $cwb_ltrim(%title%,The,A,An).

2. Make a new grouping criteria where the "Primary Sort" field is $if2([$meta(date)],%album%) and the secondary sort is %album% Have "Group by Sort" checked.  This will cause it to sort first by the year, if it is present, then by the album title.  It will also group by the same criteria (I assume all tracks in an album have the same year).  So it will sort by year, then for albums that are in the same year it will sort by the title of the album.  If there is not date field it will just sort by the title.  Alternatively you could use $if2([$meta(date)],9999) as the primary sort.  This will sort by the year if it is present, but if it isn't it will put all of those albums at the very end.  you could use 0000 instead of 9999 to put all albums without a year at the very beginning instead, or some arbitrary year to put them in the middle.  Otherwise it will behave the same.

3. This depends on hoy you tag compilation albums.  For instance if all your compilation albums have an Album Artist that is different from their regular Artist you could use

Code: [Select]
$if([%track artist%],(Compilation),%album%)


In this code if the %artist% and %album artist% fields are different %track artist% will exist and thus [%track artist%] will return a string (which $if counts as "true").  In this case it will group it into a fixed (Compilation) group no matter what other properties it has, since "(" has a higher sort priority than letters and numbers if I remember correctly.  If the %artist% and %album artist% fields are the same, in the case where there is only one artist on an album, then %track artist% is blank.  That makes [%track artist%] return a false, causing the program to group by the %album% field (you can make that whatever you want).  Note that if there is no %album artist% field, %album artist% simply displays the %artist% field and thus %track artist% will not exist.  Same is true if there is no %artist% field but there is an %album artist% field (probably a rare situation).  You can modify that initial test however you want, just as long as it either returns true or false depending on whether it is a compilation or not.