Zeka Posted September 8, 2016 Share Posted September 8, 2016 Hi. I have radio buttons with values from 1 to 10 and i need to sort page array with these values, but not ascending/descending ordering, but with custom ordering. For example: At first go pages where value of this field set to 3, then 2, then 1, then 4 and so on. Ho to accomplish it? Thanks Link to comment Share on other sites More sharing options...
blynx Posted September 8, 2016 Share Posted September 8, 2016 You could set up an array which maps your custom ordering and then loop over it and get/put your data accordingly ... !? $my_custom_order_map = array( 1 => 3, 2 => 2, 3 => 1, 4 => 4, … ); $new_order = new PageArray(); foreach($my_custom_order_map as $pos) { $new_order->append($old_page_array->eq($pos)); } best wishes, Steffen 1 Link to comment Share on other sites More sharing options...
Zeka Posted September 8, 2016 Author Share Posted September 8, 2016 @blynx Thanks for suggestion. But i did not fully understood it. Do you mean something like that? $order_map = array( 1 => 3, 2 => 2, 3 => 1, 4 => 4 ); $sorted_array = new PageArray(); foreach($order_map as $pos) { $temp_array = $pages->find("radio_field=$pos"); $sorted_array->improt($temp_array); } Link to comment Share on other sites More sharing options...
blynx Posted September 8, 2016 Share Posted September 8, 2016 hej, hmmm - could you give some more details about the situation? What is the data, what do you want to do with the data? Do you want to render a form with radio buttons from a PageArray? What I suggested was just a method to reorder whatever PageArray according to a new order - Maybe the $pages->find() shouldn't be in the loop anyway - rather before the loop to get the data once? But right now I think I need more information about the situation actually to make useful suggestions. cheers, Steffen Link to comment Share on other sites More sharing options...
Zeka Posted September 8, 2016 Author Share Posted September 8, 2016 @blynx Ohh.. okey I have options (radio) field with these values: 1=Green 2=Yellow 3=Black 4=Pink ... I have template - "product" which contains this field. I need to output list of products (pages with "product" template), but ordered by some specific order -> black (3), pink (4), green(1), yello(1). Hope that it is clear now $sorted_array = new PageArray(); foreach($order_map as $pos) { // Find pages with some value (e.q. black) $temp_array = $pages->find("radio_field=$pos"); // import pages to new array $sorted_array->import($temp_array); } Link to comment Share on other sites More sharing options...
blynx Posted September 9, 2016 Share Posted September 9, 2016 Ah ok! Then I also understand your code : ) Actually I think this should be it - I just discovered a typo! It should be "import" not "improt" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now