Splitting your main blog content into (x) multiple columns

Last modified: January 14, 2006 - 12:47

Description

Intended for use as a custom node-blog.tpl.php layout file, this snippet splits the main body of a blog into multiple columns, like a news paper article.

Usage

The snippet is a complete node-blog.tpl.php file. Copy and paste it using a text editor like notepad.exe and upload it to your active theme folder.

You can specify how many columns by editing the $columns value and the spacing in betwen columns by increasing or decreasing the $column_spacing value.

Notes:

  1. Teasers are treated normally. The multiple columns are only displayed when the user is viweing the full blog page.
  2. Recommended for use with blogs using text only in the main content. The automated column-balance doesn't work sometimes if there are images within the text
  3. The Snippet uses a HTML Table to output the columns, if you know how to achieve the same using just DIVs please post it
  4. To discuss this snippet, please post on the multiple column snippet discussion thread in the forum

<?php  $columns = 3; // number of columns ?>
<?php  $column_spacing = 8; //spacing between columns in pixels ?>

<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
  <?php if ($page == 0): ?>
    <h2><a href="/<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
  <?php endif; ?>
  <?php print $picture ?>
  <div class="info"><?php print $submitted ?></div>
  <div class="content">
    <?php if (!$page == 0): ?>
<?php
print "<table border=\"0\" cellpadding=\"$column_spacing\"><tr>";
 
$bodytext = array("$content");
 
$text = implode(",", $bodytext); //prepare bodytext
 
$length = strlen($text); //determine the length of the text
 
$length = ceil($length/$columns); //divide length by number of columns
 
$words = explode(" ",$text); // prepare text for word count and split the body into columns
 
$c = count($words);
 
$l = 0;
  for(
$i=1;$i<=$columns;$i++) {
   
$new_string = "";
    print
"<td style=\"text-align:justify\" valign=\"top\">";
  for(
$g=$l;$g<=$c;$g++) {
    if(
strlen($new_string) <= $length || $i == $columns)
   
$new_string.=$words[$g]." ";
    else {
     
$l = $g;
    break;
      }
     }
    print
$new_string;
    print
"</td>";
  }
  print
"</tr></table>"; // complete the table
?>

<?php endif; ?>
<?php if ($page == 0): ?>
  <?php print $content ?>
  <?php endif; ?>
  </div>
<?php if ($links): ?>
    <?php if ($picture): ?>
      <br class='clear' />
    <?php endif; ?>
  <div class="links"><?php print $links ?></div>
<?php endif; ?>
<div class="terms">( categories: <?php print $terms ?> )</div>
</div>

 
 

Drupal is a registered trademark of Dries Buytaert.