mirror of
				https://github.com/getgrav/grav.git
				synced 2025-10-31 10:25:59 +01:00 
			
		
		
		
	Added a new random sort order option
				
					
				
			This commit is contained in:
		| @@ -539,8 +539,14 @@ class Pages | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Sort by the new list. |         // handle special case when order_by is random | ||||||
|  |         if ($order_by == 'random') { | ||||||
|  |             $list = $this->array_shuffle($list); | ||||||
|  |         } else { | ||||||
|  |             // else just sort the list according to specified key | ||||||
|             asort($list); |             asort($list); | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |  | ||||||
|         // Move manually ordered items into the beginning of the list. Order of the unlisted items does not change. |         // Move manually ordered items into the beginning of the list. Order of the unlisted items does not change. | ||||||
|         if (is_array($manual) && !empty($manual)) { |         if (is_array($manual) && !empty($manual)) { | ||||||
| @@ -568,4 +574,17 @@ class Pages | |||||||
|             $this->sort[$path][$order_by][$key] = $info; |             $this->sort[$path][$order_by][$key] = $info; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Shuffles and associative array | ||||||
|  |     protected function array_shuffle($list) { | ||||||
|  |         $keys = array_keys($list); | ||||||
|  |         shuffle($keys); | ||||||
|  |  | ||||||
|  |         $new = array(); | ||||||
|  |         foreach($keys as $key) { | ||||||
|  |             $new[$key] = $list[$key]; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $new; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user