12 Posts
Pyro
8 years ago
1
Topic

Hello Seblod Community,

I have following Questions:

- I have a list and Search that grabs results according a Keyword

- I want to Order the resulting Articles by categorie IDs. 

     - we have several mainproduct categories (ID: 1,3,5,7,...) and accessories categories (ID: 2,4,6,8,...)

    - I tried to order by article category ID, means: all results with ID 1,3,5,7,etc... should be listed before the categories with ID 2,4,6,8

I tried to set the ordering direction to "custom" and set the options with the ids separated by coma (1,3,5,7,2,4,6,8) but i doesnt work.

Also can imagine because i do not have a separator set (,). Or am i totaly wrong with this ?

thank you for your help!

kind regards

Daniel

Get a Book for SEBLOD
154 Posts
WebOne
8 years ago
0
Level 1

Hi,

You can achieve a custom sort like this by adding the following code (amend as required) to your list template.
(note: I did not test the code but it should work).

$items = $cck->getItems();
$even = array();
$odd = array();
foreach( $items as $item ) {
if($item->getValue('your_catfield') & 1) {  // It's odd (1,3,5,7)
array_push($odd, $item);
}
else {array_push($even, $item);
}
}
$items = array_merge($odd, $even);

(add above

foreach ( $items as $item ) ... in the template)

Get a VIP membership