Skip to main content
In continuation to my previous post about "Taming Drupal Node Title and Teaser" this is part 2 of the Drupal node title and teaser taming tweak by editing node-type.tpl.php.(type is your content type like story, project or custom type like news or project etc). This is what your teaser for front page look like after the tweak is applied and after some great theming :-).

The previous Node title and teaser tweak works for content types that have just two fields Node Title and Node body and may be file attachments. Now picture a custom node type called project that has node title, node body, a link to the project and a screen-shot of the project. In that case the previous tweak will not give desired output so here is the code to tweak your title and teaser.

In this tweak if the last character is space then it will also be cut/omitted from the display making it look better like it would display "Saathi Sanga..." rather than "Saathi Sanga .." the space there. As the previous tweak it is targeted for teaser for the homepage.

For this teaser tweak the node-body must be shown first so that it can be extracted and separated from the body. Your CCK field weighs (ordering) should look something like below putting the body above other custom fields:
It was done in Drupal 6 but for Drupal 5 also see that Body is above other fields you created.

For node title length control, in your node-type.tpl.php use the following code by replacing


WITH following code, download the code in txt file at the end:

The above code will make your teaser be of just 12 characters for the front page only.

Similarly, for the node teaser length control for the front page, in the node-type.tpl.php replace:

WITH (Code downoad in .txt form at the end)

The tweak will make your teaser just 66 characters for the front page.This tweak will not affect your teasers on other pages than the front page and your full nodes. The above tweak is done on a website that had FCK editor enabled in case if FCK editor or any WYSIWYG editor is not active then wrap your paragraphs in
tag for the script to work.


The teasers on other page will appear like below:
To make it look this cool you must do great theming.

Get the code in .txt format here (opens in new window), or see it here. (Links open in new window)

The text file is also uploaded to scribd here if you want to analyze the code in full screen flash interface.

I hope it helps your Drupal development and custom Drupal Theming, HAPPY THEMING.

Comments