• I am use A-Z Listing to construct an index of my posts that is grouped by category and, within each category, is sorted alphabetically. However, I have one category that is more naturally sorted by post date. How can I do this? I tried the advanced option “Use a customized comparison function for sorting the index”, but I don’t know enough PHP to construct such a comparison function or to know if such a function already exists.

    Many thanks for any help, and for this useful plugin.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dani Llewellyn

    (@diddledani)

    Hi,

    I don’t think I really understand the concept here, but that is probably me just misunderstanding, so please forgive my deficiency ?? I’ve tried to outline some thoughts below anyway.

    The plugin will sort the listing alphabetically by default. Even if you customise the sorting mechanism the customisation will apply to an entire A-Z List and cannot affect a single sub-section. If you have multiple A-Z Lists you can apply customizations to each full-list independently of the others via judicious add_filter() and remove_filter(), but cannot affect just a small part of each list.

    The comparison function works the same as PHP’s usort() function, where the function takes two parameters and if the first is to appear in the list first then it returns -1, if both items are equal in their value and so there is no requirement for one to have precedence over the other then return 0, and if the second item should appear first then return 1.

    The idea I had when I implemented that customisation was to allow for languages where it is less clear what the order should be to PHP so I allow the site owner to add logic to sort the items into their preferred order. For example, if a language has characters which are ordered differently in the Unicode numbers to their preferred local system then the site owner can create a function to ignore the Unicode numbers and order the titles arbitrarily based on the -1, 0 and 1 comparison of PHP’s usort() function.

    Thread Starter jessriedel

    (@jessriedel)

    Hi Daniel,

    The page looks like this

    <h3>First category</h3>
    [az-index id="1"]

    <h3>Second category</h3>
    [az-index id="2"]

    <h3>First category</h3>
    [az-index id="3"]

    I believe you would describe the above as “having multiple lists”. I would like just one of these lists, produced by a single az-index shortcode and corresponding to a single category, to be ordered by the date the post was published rather than the title of the post. I am led to believe this is possible because “Use a customized comparison function for sorting the index” is an option available for a single list.

    Unfortunately, I know essentially zero PHP. I know this is partially asking you to do my work for me but, if it’s not to hard, I would be grateful if you could tell me what custom comparison function I should use. This might be an existing named function, or (I think) it might involve writing a new (one-line) function inside the functions.php file in my current theme.

    Thanks for any help you can provide.

    Plugin Author Dani Llewellyn

    (@diddledani)

    Aha, I think we’re talking cross-purposes here. It looks like you’re using a different plugin, not mine ?? Your page has an identification that you’re using AZIndex, whereas my plugin is A-Z-Listing. I think you probably want to talk with “English Mike” over at https://azindex.englishmike.net because I don’t have anything to do with that plugin so probably can’t help you very well with customising it, though I will help as much as I can.

    Thread Starter jessriedel

    (@jessriedel)

    Ha, very embarrassing. Thanks for the pointer and sorry for wasting your time!

    Plugin Author Dani Llewellyn

    (@diddledani)

    Don’t worry, it’s not a problem at all. If I can still help in any way, I will try to do so.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to sort index of single category by date’ is closed to new replies.