I have been working on this project, www.newsafrican.com which is a news site which focuses on everything african news. This project is been built on the Drupal CMS which is very flexible arguably.
I got into a situation where i have to customise the teaser length by View which happens to be one of the Drupal modules using node.tpl.php.
One way to vary teaser lengths is to check the current View with a modified node.tpl.php modify the output based on this
In this example a teaser of length 75 or 150 will be shown for the Views “frontpage” and “ghana_page” respectively.
I worked on this for Drupal 5 with the help of the good guys in the drupal IRC rooms, my solution is below. But this is a solution for Drupal 6 by friends on the drupal-support channel of IRC.
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
<?php if ($page == 0): ?>
<?php else: ?>
<?php print $picture ?>
<em class="info"><?php print $submitted ?></em>
<?php endif; ?>
<?php
global $current_view;
if($teaser) {
if($current_view->name == ‘frontpage’)
{?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content['body']['#value'];
}
if($current_view->name == ‘ghana_page’)
{?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content['body']['#value'];
}
if($current_view->name == ‘africa_page’)
{?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content['body']['#value'];
}
if($current_view->name == ‘business_page’)
{?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content['body']['#value'];
}
if($current_view->name == ‘gh1′ || $current_view->name == ‘gh2′)
{?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print substr($node->content['body']['#value'], 0, 90). ‘ ’;
?><a href=”<?php print $node_url ?>” title=”read more”>read more</a><?php
}
} else {
print $content;
}
?>
LOL, I remember helping you in IRC… now I go to do a search on Google looking for the same thing, and you’re helping ME!
Thanks for posting this. Best of luck with your news site
It looks great!
Comment by heather — October 8, 2008 @ 11:31 am
hey dude thnx man. yeah i remember u.
Comment by egoleo — November 17, 2008 @ 1:00 pm
Hey, thanks for providing this.
It looks like you may have left out the part where you trim the body string, though…
Comment by Jeff Schuler — January 10, 2009 @ 12:06 am
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
Comment by Alexwebmaster — March 3, 2009 @ 9:22 am