WordPress.org

Forums

AZIndex
Ignore "The" before entries. - SOLVED (1 post)

  1. seanmolin
    Member
    Posted 2 years ago #

    The "ignore character" option is nice, but doesn't work for words... only individual characters. Well, I figured out a nice, clean, simple solution to having the sort function ignore the word "The" properly.

    Add the following to your theme's functions.php:

    add_filter('azindex_item', 'ignore_prefix');
    
    function ignore_prefix($item) {
    $item['sort-head'] = str_replace('The ', '', $item['sort-head']);
        return $item;
    }

    You will need to refresh the index cache before it sorts the headings properly, but otherwise that's it. I'm sure it wouldn't be hard to add the ability to ignore "A" and "An" if that's a need... but for me I only need "the". Just be sure to have that space after the word you are calling so that it only removes them as full words and not in the middle of a word (e.g. 'Theme' being sorted as 'me.')

    Because "sort-head" affects the sort key and not the displayed string, there is no visible penalty if it removes "the" in other places. The output doesn't have any words removed... only the code underneath.

    You can see a working example here: http://concART.net/artists

    http://wordpress.org/plugins/azindex/

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • AZIndex
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic