Quick Tip: Displaying only one CCK image in your teaser

For my Drupal 6 web site,  Green Ninja Active City Guides, I have several CCK content types that all have multiple images. Each of these uses the same field, (field_pictures), and I use jQuery Gallery Formatter to create a scrollable picture gallery on my Race, Park, and Trail content types.

I’m getting larger amounts of photos on some of my nodes now, for instance, the Cactus Rose 50 Mile and 100 Mile Race page, and that’s starting to slow performance. The jQuery Gallery Formatter really slows down my pages, so I switched my teaser views to just display the images with the node. That works great for nodes with one or two images, but looks horrible on pages like San Antonio Trail Running – where users have to scroll through all thirty of the Cactus Rose photos to get to the next race.

Ideally, CCK Imagefield would have a display option like “first image” or similar. The problem, as discussed on here: is that the CCK formatters don’t take configuration parameters, so to add this, the formatter would have to double the number of formatters in the drop down box. ImageCache already adds formatters for each image size you support, as do several other modules.

As that solution isn’t available to me, I went ahead and created my own solution by modifying my node-race.tpl.php.

First, I changed my Display Settings on Race to exclude my Pictures field from $content so the entire list doesn’t get displayed. Check the first “Exclude” checkbox for your field, but not the second – that will exclude the images from your full node display as well.

Next, I made a slight modification to my node-race.tpl.php file. Decide where on your display you would like the thumbnail to go and add this code:

<?php if ($teaser): ?>

      <?php print $field_pictures[0]['view']; ?>

<?php endif; ?>

replacing field_pictures with field_NAMEOFYOURCCKFIELD.

That’s all you need to do! Clear your cache if you’re running into difficulties seeing the change.


Impressed by WordPress so far

I’m currently working on several Drupal 6.x web sites, but to broaden my knowledge, I decided to use WordPress for my personal/professional web site. I don’t want to get tied to just one way of doing things or thinking, and I’d also like to be able to recommend the right CMS for a project.

Drupal was actually easier to install than WordPress  3.0.1, which sounds funny, but I was really surprised that WordPress didn’t let you set up the database from a PHP page instead of from a configuration file. Not a big deal for me, but it seems like that’s the norm for PHP CMS installs these days.

The out of the box WordPress Post creation UI is much, much cleaner than the out of the box Drupal 6.x Post Creation UI. Partly this is because WordPress is more focused, but there is a lot you have to do to Drupal just to get a WYSIWYG editor in place with image uploads – try it and see. And even when you do get that set up for a content creator, the UI is complicated and difficult to understand.

So far I also like the WordPress Admin dashboard – Drupal 6.x needs something similar out of the box, where modules can register alerts or notifications of things that need to be done. I had something similar in a Ruby on Rails web application that I built a few years ago, but it was all custom code.

I’m still exploring WordPress, but I don’t intend to do a lot to this site with plugins or themes, so I probably won’t get to see a lot of the differences between Drupal and WordPress with extensibility.