Community Documentation

Two columns of teasers

Last updated August 23, 2009. Created by Bèr Kessels on July 25, 2005.
Edited by SLIU, domesticat, Dublin Drupaller. Log in to edit this page.

These snippets allow you to show nodes in two columns on any teaser listing page. It works for PHPtemplate

in template.php add:

function _exampletheme_nodebreak($node) {
  static $count;
  if ($node->sticky) {
   return TRUE;
  }
  else {
    $count = is_int($count) ? $count : 1;
    $return = ($count % 2) ? FALSE : TRUE;
    $count++;
    //dprint_r('WOOT');
    return $return;
  }
}

in node.tpl.php add to the end (after all the node content)

<?php if (($page == 0) && _exampletheme_nodebreak($node)): ?>
<br class="clear" />
<?php endif; ?>

And add to your style.css, a something like:

#contentcenter .node.teaser {
  float: left;
  width: 223px; //for fluid layout use 50%
  margin-left: 20px; //for fluid layout set to 0;
  padding: 0;
}

Note that you can play aroun with the values and make it a three column mayout without much hassle too.

Comments

it IS working, but

It works, but you'll have to adjust the css, in order to make it work with your theme. For Garland (the default theme in 5) it is something like:

.node {
  float: left;
  width: 223px; //for fluid layout use 50%
  margin-left: 20px; //for fluid layout set to 0;
  padding: 0;
}

better solution

The disadvantage of this method is the gaps that it produces. (When, on the same row, a short teaser on the left side is paired with a long teaser on the right side, there will be a gap under the text on the left side, because the next row will start under the longest article).

It's probably better and easier to use the views module with the views bonus pack (http://drupal.org/project/views_bonus) and the frontpage module. It allows you to create a node with a view (views module) that can be divided into columns with the help of so called panels (views bonus pack). This page can be turned into the frontpage (frontpage module).

Page status

Needs updating

Log in to edit this page

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here