In Views 1 is there a way for nodes to be sorted alphabetically by title without including words like "The" at the beginning?

I considered Views Custom field and was able to create a field that stripped off preceding "The"s where they occurred. However, the Views Custom field value does not appear to be an option within sort criteria.

Thank you for your thoughts!

Comments

B747’s picture

http://drupal.org/project/views_natural_sort could well be what you're looking for.

ecksley’s picture

Thank you B747!

I'm maintaining a site in D5 so that won't work, but it's great to know for all the new sites I build.

Here is what I ended up doing it for those that care:

  • Changed the node titles in question from "The Cat" to "Cat, The"
  • This allows the standard title sort to work without the "The"
  • Create the following reprocess function in template.tpl.php to reassemble titles correctly:
    <?php
    function shopZen_preprocess(&$vars, $hook) {
      $vars['sample_variable'] = t('Lorem ipsum.');
      $title = $vars[title];
      if (substr($title, -5)==", The"){
      	$vars['title'] = "The ".substr($title, 0, -5);
      } else if (substr($title, -3)==", A") {
      	$vars['title'] = "A ".substr($title, 0, -3);
      } else
      	$vars['title'] = $title;
      }
    }
    ?>
    
  • Install Views Custom Field.
  • Replace the page title field wherever it appears in Views with a Views Custom Field with similar code to what you see above where possible.

What a pain. Thanks again for the response!