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
Check out the Auto Node Title module
http://drupal.org/project/auto_nodetitle
On Sun, Aug 1, 2010 at 12:07 PM, Benjamin Jacob ben4asterisk@yahoo.comwrote:
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/ ]
Hi,
The "Page Title" module is pretty flexible: http://drupal.org/project/page_title
It allows you to use tokens, I'm using the following site wide: Sofika.com: [page-title]
You can target pages of specific content types or pages assigned to a vocabulary term. Also allows you to enter a pattern that "will be appended to a page title for any given page with a pager on it".
Joe
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@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
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@drupal.org [mailto:support-bounces@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
Thanks guys for your responses. Will try the regex thing for sure. I am not sure if either page title or automatic nodetitles solve my problem off-the-shelf.
This is pretty common in different listings, e.g. book listing, video/movie listing, etc. e.g. The Final Frontier = Final Frontier, The 24 Chowringee Lane = Chowringee lane, 24 etc.
Quite surprising that (as I say) off-the-shelf modules are not available with Drupal. I am not a PHP/Drupal expert (as of yet) but can write this in C/C++ in a jiffy. I hope some of you experts take note :-)
This can be an added feature in the existing modules you described, where the user can specify different tokens (extracted from the title) he/she wants to be appended to the title.
Thanks again. - Ben
--- On Mon, 8/2/10, Joe CodeWaggle joe@codewaggle.com wrote:
From: Joe CodeWaggle joe@codewaggle.com Subject: Re: [support] node titles - move "the", numbers to the end To: support@drupal.org Date: Monday, August 2, 2010, 4:45 AM 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@drupal.org [mailto:support-bounces@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/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
If you want to use this within the context of a Views listing, you should have a look at the Views Natural Sort module ( http://drupal.org/project/views_natural_sort). That module might be able to help you out of the box. This won't change the node title on the detail page though...
Sven
On Mon, Aug 2, 2010 at 5:23 PM, Benjamin Jacob ben4asterisk@yahoo.comwrote:
Thanks guys for your responses. Will try the regex thing for sure. I am not sure if either page title or automatic nodetitles solve my problem off-the-shelf.
This is pretty common in different listings, e.g. book listing, video/movie listing, etc. e.g. The Final Frontier = Final Frontier, The 24 Chowringee Lane = Chowringee lane, 24 etc.
Quite surprising that (as I say) off-the-shelf modules are not available with Drupal. I am not a PHP/Drupal expert (as of yet) but can write this in C/C++ in a jiffy. I hope some of you experts take note :-)
This can be an added feature in the existing modules you described, where the user can specify different tokens (extracted from the title) he/she wants to be appended to the title.
Thanks again.
- Ben
--- On Mon, 8/2/10, Joe CodeWaggle joe@codewaggle.com wrote:
From: Joe CodeWaggle joe@codewaggle.com Subject: Re: [support] node titles - move "the", numbers to the end To: support@drupal.org Date: Monday, August 2, 2010, 4:45 AM 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@drupal.org [mailto:support-bounces@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/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
On Aug 2, 2010, at 8:23 AM, Benjamin Jacob wrote:
This is pretty common in different listings, e.g. book listing, video/movie listing, etc. e.g. The Final Frontier = Final Frontier, The 24 Chowringee Lane = Chowringee lane, 24 etc.
The common pattern is to move articles (A/An/The) to the end, and to decide what to do with numbers separately -- some places just have a "#" section, others alphabetize the title as if the number were spelled out (twenty-four). In your example, "24" is a useful part of the title and not just a formality required by the syntax of the language; I wouldn't move those numbers to the end. Also, what about movies that spell out their numbers? Would you list them as, for example, "Element, The Fifth"? "Days Seven Nights, Six"? You're getting into some complicated territory here :)
As far as doing what you want to do, I think auto nodetitle will work fine. It has the option to generate the title with custom php if you want; that should be more than enough.
HTH, -D
:-)
I get the picture. I agree... somewhat. Thanks. This definitely does help.
- Ben
--- On Mon, 8/2/10, Domenic Santangelo domenics@gmail.com wrote:
From: Domenic Santangelo domenics@gmail.com Subject: Re: [support] node titles - move "the", numbers to the end To: support@drupal.org Date: Monday, August 2, 2010, 3:51 PM On Aug 2, 2010, at 8:23 AM, Benjamin Jacob wrote:
This is pretty common in different listings, e.g. book
listing, video/movie listing, etc.
e.g. The Final Frontier = Final Frontier, The 24 Chowringee Lane = Chowringee lane, 24 etc.
The common pattern is to move articles (A/An/The) to the end, and to decide what to do with numbers separately -- some places just have a "#" section, others alphabetize the title as if the number were spelled out (twenty-four). In your example, "24" is a useful part of the title and not just a formality required by the syntax of the language; I wouldn't move those numbers to the end. Also, what about movies that spell out their numbers? Would you list them as, for example, "Element, The Fifth"? "Days Seven Nights, Six"? You're getting into some complicated territory here :)
As far as doing what you want to do, I think auto nodetitle will work fine. It has the option to generate the title with custom php if you want; that should be more than enough.
HTH,
-D
[ Drupal support list | http://lists.drupal.org/ ]
I built upon the suggestion given by Domenic below.
I added a CCK text field called My Title in my node type. Setup Automatic File generation using Automatic Node titles module. Selected "Automatically generate the title (default node element) and hide the title field" and setup PHP (selected "Evaluate PHP in pattern.") code for the auto generation of the title using My Title's value entered by the user.
<?php $customTitle="[field_my_title-raw]"; $customTitle=trim(preg_replace("/\s\s+/"," ",$customTitle)); $customTitle=preg_replace("/^(the|a|an)\b\ (.*)/i","$2, $1",$customTitle); print "$customTitle"; ?>
cheers - Ben
--- On Mon, 8/2/10, Benjamin Jacob ben4asterisk@yahoo.com wrote:
From: Benjamin Jacob ben4asterisk@yahoo.com Subject: Re: [support] node titles - move "the", numbers to the end To: support@drupal.org Date: Monday, August 2, 2010, 4:11 PM
:-)
I get the picture. I agree... somewhat. Thanks. This definitely does help.
- Ben
--- On Mon, 8/2/10, Domenic Santangelo domenics@gmail.com wrote:
From: Domenic Santangelo domenics@gmail.com Subject: Re: [support] node titles - move "the",
numbers to the end
To: support@drupal.org Date: Monday, August 2, 2010, 3:51 PM On Aug 2, 2010, at 8:23 AM, Benjamin Jacob wrote:
This is pretty common in different listings, e.g.
book
listing, video/movie listing, etc.
e.g. The Final Frontier = Final Frontier, The 24 Chowringee Lane = Chowringee lane, 24 etc.
The common pattern is to move articles (A/An/The) to
the
end, and to decide what to do with numbers separately
--
some places just have a "#" section, others
alphabetize the
title as if the number were spelled out (twenty-four).
In
your example, "24" is a useful part of the title and
not
just a formality required by the syntax of the
language; I
wouldn't move those numbers to the end. Also, what
about
movies that spell out their numbers? Would you list
them as,
for example, "Element, The Fifth"? "Days Seven Nights,
Six"?
You're getting into some complicated territory here
:)
As far as doing what you want to do, I think auto
nodetitle
will work fine. It has the option to generate the
title with
custom php if you want; that should be more than
enough.
HTH,
-D
[ Drupal support list | http://lists.drupal.org/ ]
[ Drupal support list | http://lists.drupal.org/ ]