User login

The easiest way to do CCK teasers!

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

Resolution

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

Searched words: 
CCK teasers drupal theming node.tpl template if

Comments

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:-)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.