The easiest way to do CCK teasers!

Key words and phrases: 
CCK teasers drupal theming node.tpl template if
Description & Info: 

So, if you're reading this then you've most likely followed this (http://agaricdesign.com/theming-cck-the-agaric-way) excellent guide written by my esteemed colleague Ben, and now you've got yourself some kick ass custom themed cck nodes.

Well what if you want teaser views of those same nodes for building views or some other reason? Granted you can live without the traditional 'teaser' system, you can easily put an if statement in the node-whatever.tpl.php that you've created to break it up into a teaser section and a page section...

What do I mean by this you ask? Well, let's say you've setup a 'portfolio' content type on your site complete with custom cck fields. Let's say there are fields now for an image, a date, and a description. Now let's assume that you're going to have plenty of 'portfolio' content and you want your users to easily be able to browse through it. You can easily setup a view that shows the latest 'portfolio' content but the listings are all going to be full nodes complete with description and everything.

What we're going to learn today is how to create a teaser section that can be used by the view to display nice listings of nodes with just a picture and a date, leaving the description field to only be displayed only on the node itself...

make sense? I hope so... besides I'm a web designer not an english major...

The solution is pretty easy. Just modify your newly (or maybe not so newly) created node-whatever.tpl.php with an if statement

<?php if ($page == 0): ?>
then the fields you wish to display for a teaser body
<?php else: ?>
then the fields you wish to display for the node body

<?php
endif;
?>

I've attached a copy of a tpl file with the above implemented, so don't say I never did anything for you...

AttachmentSize
node-portfolio.tpl.php.txt3.01 KB
Thank you!

I came across your page after a long search on how to remove taxonomy terms from teasers. Congratulations on the great resources you have compiled here. You've just got another registered user:-)

Posted by pauldolphin (not verified) on Sat, 2008-02-16 11:56
Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
  _   ____    _____  _____   _____ 
/ | / ___| |__ / |___ | | ___|
| | \___ \ / / / / | |_
| | ___) | / /_ / / | _|
|_| |____/ /____| /_/ |_|
Enter the code depicted in ASCII art style.