Forums
Home / Plugin: Library Viewer / Sorting
(@johansam)
2 years, 9 months ago
Is it possible to sort the output?
(@pexlechris)
How you mean? Do you want the folders first and then the files? The files first and then the folders? How do you think it? If you specify more details I can give you the specific hook to do it with php
For instance, I would like to sort on the file names in the file list. Or on the file creations date. Or on the folder names.
Have look at https://mariefredbk.hemsida.eu/index.php/styrelseprotokoll/?dir=Styrelseprotokoll%2F2021
What if I want to show the files in revers order ie the newest file at the top?
You can use the filter lv_containing_files. You can see in my documentation here: https://www.pexlechris.dev/library-viewer/docs/hooks/?library-viewer=yes#lv_containing_files in order to revert the array and return the reverted array.
You can use the php native function array_reverse . Doc here: https://www.php.net/manual/en/function.array-reverse.php
Something like:
add_filter('lv_containing_files', function($arr){ $arr = array_reverse($arr); return $arr; });
In order to add the above hook in your site, read the following tutorial: https://www.pexlechris.dev/how-to-add-php-hooks-in-your-wordpress-site/