JUST OPEN SOURCE MATTERS!

September 8, 2008

Custom teaser length by View using node.tpl.php

Filed under: drupal, open source — Tags: , , , , — egoleo @ 5:23 am

I have been working on this project, http://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). ‘&nbsp;’;
?>
<a href=”<?php print $node_url ?>” title=”read more”>read more</a><?php
}
} else {
print
$content;
}
?>

15 Comments »

  1. 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

  2. hey dude thnx man. yeah i remember u.

    Comment by egoleo — November 17, 2008 @ 1:00 pm

  3. 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

  4. 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

  5. Hello, What a fantastic site, and a brilliant but simple idea! … egoleo.wordpress.com viagra shop – vwyj – 46492 111 Patients taking tadalafil consistently had numerically higher levels of therapeutic effectiveness and satisfaction compared with patients who took sildenafil or vardenafil.The most useful study involved treating 33 postmenopausal women who complained of sexual dysfunction with Viagra for a time period of three months.Men too are expected to be able to get erections no matter what.Today it would strike many people as plain weird that a man might choose to live with erectile dysfunction. viagra prescription cialis levitra sales viagra viagra research cheap viagra online viagra uk 16087 – fo vvi.ag.ra- ccia.llis , how vvi.ag.ra- works
    look this Efficacy was assessed at weeks 4,8, and 12 using a newly developed 9-iem, self-administered Index of Female Sexual Function (IFSF) and a global efficacy question.Our study suggests that oral sildenafil monotherapy is effective in improving exercise capacity and health-related quality of life amongst PAH patients.Shafiei, M / Mahmoudian, M / Rostami, P / Nemati, F, Acta physiologica Hungarica, Mar 2006 The effects of an intraperitoneal (i.p.) injection of different doses of sildenafil, a cyclic guanosin monophosphate (cGMP) specific phosphodiesterase type 5 (PDE 5) inhibitor, on memory retention of young (2-month-old) and middle aged (12-month-old) male …Three relevant issues are discussed: (1) Male-female differences in sexuality.Quiram P, Dumars S, Parwar B, Sarraf D. G’night

    Comment by LiceFerenerty — January 21, 2010 @ 5:22 pm

  6. En trevlig k√§nsla blir rikligare √§n Viagra ‚ĄĘ. De som anv√§nt Viagra f√∂rst√•r, k√§nslan av tr√∂tthet efter ett samlag √§r stark, och det finns pl√∂tsligt svag och besv√§rande k√§nsla. De k√∂nshormoner ingrediensen av kemikalier, inte ing√•r i och Satibo Kapsel justerar k√∂n funktionen hos en m√§nniska som med metoden f√∂r att st√§rka uts√∂ndringen f√∂rm√•ga egna hormon helt egen potentiell makt fullst√§ndigt klarlagts, och en rik k√§nsla av samlag produceras . Detta√§r en stor charm Satibo Capsule.

    Comment by George — July 19, 2010 @ 3:44 pm

  7. very good thanks you admin

    Comment by Brand Viagra — November 29, 2010 @ 2:48 pm

  8. ZewQem http://dy5Ndo9BsL1vpVv5kqsUh.com

    Comment by samuel — April 7, 2011 @ 3:40 pm

  9. 8XyAjY http://fnYwlOpd2n9t4Vx6A3lbk.com

    Comment by geoge — July 28, 2011 @ 5:37 pm

  10. Who would I report to? pedo models
    >:-[[

    Comment by Grhldirx — September 7, 2011 @ 11:39 pm

  11. Gloomy tales Youngest Nymphets >:-))

    Comment by Ptffzkio — September 21, 2011 @ 8:12 am

  12. I’ve got a very weak signal Underage Incest Stories Free 407

    Comment by Udwghhyv — September 22, 2011 @ 8:53 am

  13. A pension scheme Pedo Blowjob >:[

    Comment by Vcayiwfn — September 22, 2011 @ 9:30 pm

  14. I’d like to send this to http://rosydodyjy.de.tl topless playboy model Pinky is hella fine… i wanna eat her PUSSY so bad… DAMN SHE THE SHIT… THAT FAT ASS CLAPPIN AND SHIT…

    Comment by Xgbxrgwm — May 2, 2012 @ 5:22 pm

  15. I have got 1 idea for your web site. It looks like right now there are a number of cascading stylesheet troubles when launching a selection of web pages inside google chrome and internet explorer. It is working alright in internet explorer. Possibly you can double check this.

    Comment by click here — May 27, 2012 @ 4:53 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: