Document library sort options
Document Library Pro comes with two options for sorting the document library when it first loads. These appear in Documents → Settings → Display.
Once the library has loaded, users can click on a column heading to sort by that column.
Sort by
The sort_by
option sets which column should be used for sorting the library by when it is first displayed. Defaults to date
which is the date the document was published.
You can order by any column in the library, or by any of the following keywords (whether or not they are included in your library):
id
– sort by document IDtitle
– sort by document titlemenu_order
– sort by the ‘order’ option (as listed in your site's primary menu)date
– sort by the publish date of the document (note: see here to sort by custom field date columns)name
– sort by document ‘slug’modified
– sort by last modified datecomment_count
– sort by number of commentsrand
– random order
In addition, if you are not using the lazy load option, you can sort by any other text-based column present in the library. E.g. sort_by="content"
.
For lazy loaded libraries, you can only sort by the keywords listed above. This is because the sorting is handled by the server when the products are retrieved from the database.
Examples
Sort using keyword: [doc_library content="title,content" sort_by="menu_order"]
Sort using content column in library: [doc_library content="image,title,content,doc_author" sort_by="content"]
Sort using custom field column in library: [doc_library content="image,title,excerpt,cf:event" sort_by="cf:event"]
Sort order
The direction to use for sorting by when the library is first displayed. Can be either asc
for ascending order or desc
for descending order.
Defaults to desc
for date-based sorting, and asc
for everything else, but you can override using this option. For example, if you wanted to alphabetize the library by listing items in alphabetical order, then the default will be correct.
Example
[doc_library content="title,content" sort_by="date" sort_order="asc"]
How to sort by date or number
Yes, if you're using the table layout then you can sort custom taxonomy or custom field columns by number or date. To do this, open the advanced column options for that column, and change the 'Column type' to 'Number' or 'Date'.
You may also wish to change the date format.
Can I sort by multiple columns?
No, this is not currently possible. The library can only be sorted by a single column.
Sorting folders
Document Library Pro also has a Folders option, in which the documents appear within folders based on their categories.
On the plugin settings page, you can sort the folders by folder name, category ID, category slug, category order (menu order), and the number of terms. Select the sorting direction to choose the sorting order (i.e. ascending or descending).
There are also folders_order_by
and folders_order
shortcode options which you can use to set the sort type and directly in the shortcode, with the following options
- folders_order_by options:
title
- category nameterm_id
- category IDslug
- category slugterm_order
- category order (menu order)count
- number of terms
- folders_order options:
asc
- sort in ascending orderdesc
- sort in descending order
For example, the shortcode [doc_library folders="true" folders_order_by="count" folders_order="desc"]
would list documents in folders, with the folders with the most numbers of documents first.
Sorting the content of category and taxonomy columns
If a document has more than one terms selected for a category or taxonomy, then these will appear as a comma separated list in the category/taxonomy columns of the document library. They are listed in alphabetical order. For example, a document with 3 categories might have them listed as "Presentations, Training, Videos".
If you'd like to change this then you can use a plugin such as Custom Taxonomy Order.