How to customize textfield to be multi-column
Split a text field into multiple columns, like a newspaper/magazine article.
description
This recyclable snippet allows you to automatically convert a textfield in your custom-layout.tpl.php files to newspaper style columns.
This has been tested and works with Drupal 4.5.x, Drupal 4.6.x and Drupal 4.7.
usage
The code (called the drupalicious_convert2columns function) sits in your template.php file so you can call it from various tpl.php layout files, such as node.tpl.php, node-image.tpl.php, flexinode.tpl.php etc. using just one simple line of code.
The drupalicious_convert2columns function uses a simple table to convert your text field to columns. (A DIV version of the same will follow.)
Step 1 of 2
In a text editor like notepad.exe, create a file called template.php using the following snippet. If you already have a template.php file, simply add it to your existing one.
<?php
function drupalicious_convert2columns ($colcontent, $columns, $column_spacing) {
$coloutput = "
";
$bodytext = array("$colcontent");
$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
