[support] node titles - move "the", numbers to the end

Joe CodeWaggle joe at codewaggle.com
Mon Aug 2 04:45:25 UTC 2010


Had another thought:

You can use a PHP regex function to manipulate the title, try
preg_replace().

Assuming that your template is based on phptemplate (the Drupal default
template engine), you can work in the "template.php" file in your theme
folder (you can create one if none exists).

Use the hook for _preprocess_page():
phptemplate_preprocess_page(&$vars) or ( "your template
name"_preprocess_page(&$vars) ).

Work with $vars['title'].

Code Example:
phptemplate_preprocess_page(&$vars) {
  // Manipulate the Page Title
  $current_title = $vars['title'];
  $searchPattern = '/(.*)(\sthe\s)(.*)/';

  $new_title = preg_replace($searchPattern, '$1 $3$2', $current_title);
  $vars['title'] = $new_title;
}

The search pattern looks for " the ". It keeps track of the parts of the
title, so you can rearrange the pieces.

If $current_title was 'where is the yummy candy', 
$new_title would be 'where is yummy candy the'.

Part one($1) contains 'where is', part two($2) contains ' the ' and part
three($3) contains 'yummy candy'.

Regular Expressions can get pretty involved, so if you haven't used them
before you'll need to spend some time learning how to create the search
pattern that you need.

Here are a few links to the PHP manual:
http://www.php.net/manual/en/book.pcre.php
http://www.php.net/manual/en/function.preg-replace.php
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php

A quick Google for "regular expression" or regex will turn up tons of info.

Joe


-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Benjamin Jacob
Sent: Sunday, August 01, 2010 2:08 PM
To: Drupal Support MailList
Subject: [support] node titles - move "the", numbers to the end


Hi,

Any way in drupal to manipulate titles so as to have words like "the"/"a",
and numbers to the end?


Thanks in advance.
- Ben


      
-- 
[ Drupal support list | http://lists.drupal.org/ ]



More information about the support mailing list