Last updated August 23, 2009. Created by joachim on March 11, 2006.
Edited by SLIU, Jeff Burnz, kingandy, bekasu. Log in to edit this page.
You can give a teaser its own unique look by using the following condition on any node.tpl.php file:
<?php
if ($teaser) {
// node is being displayed as a teaser
// Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
} else {
//all other cases
//Anything here will show up when viewing your post at any other time, e.g. previews
}
?>Or, if you want to use HTML within the conditions, for example to make two completely different layout within the template:
<?php if ($teaser): ?>
<!-- teaser template HTML here -->
<?php else: ?>
<!-- regular node view template HTML here -->
<?php endif; ?>$teaser vs $page
Note that the $page variable indicates whether a node is standing alone or not, which isn't necessarily the same as whether it's being shown as a teaser. There are legitimate situations where $page == 0 and it's not supposed to be a teaser - for example, when you preview a node. Additionally, $page and $teaser can be set directly by any code that displays nodes via the node_view() function, so it's wise to think about unexpected combinations.
If you wish to provide a third layout for when the node is being displayed as neither a teaser nor a page, try this:
<?php
if ($teaser) { //if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
} elseif ($page) { //if node is being displayed as a full node
//Anything here will show up when viewing only your post
} else { //all other cases
//Anything here will show up when viewing your post at any other time
}
?>
Comments
Hi,Thanks for the code. I am
Hi,
Thanks for the code. I am using the IF statement and that is working great on my node-TYPE.tpl.php except for one thing: the title is showing twice when I am taken to the page of the node. Thanks.
Youssef
<?php if ($teaser): ?>
<h4><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h4>
<div id="phone-style"> <?php print $node->field_phone[0][view]; ?> </div>
<div class="column grid_4"> <?php if (user_access('rate content')) { print fivestar_widget_form($node);} ?> <br /></div>
<?php else: ?>
<div>
<div id= "content">
<div class="row">
<div class="column grid_12">
<div class="row">
<div class="column grid_6"> <h1><?php print $title ?></h1> </div>
<div class="column grid_6"> <?php print $terms ?> </div>
</div>
</div>
</div>
.........
Title
The title is set in the page.tpl.php, so it is displayed twice when you output it in your node template.
Thank you. Youssef
Thank you.
Youssef
Any thoughts why when I click
Any thoughts why when I click on on of Taxonomy Terms, example "MP3", The title for this taxonomy page is not showing. Thanks.
Is this still relevant for version 7.x?
Is this still relevant for version 7.x? If not what has changed?
Drupal 7.0
Please discard. Thanks.
Please discard.
Thanks.
Hi, I created a
Hi,
I created a node-nodetype.tpl.php for my content type and place it in my theme file. I am able to customize my node template but when I inserted
<?phpif ($teaser):
?>
<?php" rel="nofollow">print $node_url;
?>
<?phpprint $title
?>
<?phpprint $node->field_nodetype_date[0]['view']
?>
<?phpprint $node->field_nodetype_remarks[0]['view']
?>
<?phpelse:
?>
This does not print the teaser. I went to views to print the node teaser and it print nothing. Can someone help me if I am doing something wrong as I am still in the learning phase.
Prerna
Prerna.
Show teaser in their own page for every node of a content type
I would like to show the node teaser in the standalone page, instead of the full node, but not sure how to accomplish it. Additionally, I would like to open the full text in a modal box. I know how to accomplish that for a manually added link, but how to achieve that programmatically for all "Read More links" of a content type?
I appreciate any help on this one.