I have approximately 20 content-taxonomy check boxes from one field ("features"). The checked terms display in node-example.tpl.php. I am trying to show these content-taxonomy terms in a two column list displayed/sorted in a downward order instead of across.

I am trying to use two bits of code to accomplish this...but my php skills are not yet up to the challenge. I can't get all of the array values generated in the foreach loop to be recognized by the second section of code. Any help / pointers greatly appreciated.

Thanks

The code below was taken (and modified) from the following sources:

http://drupal.org/node/312812

http://www.roscripts.com/PHP_display_data_on_columns-127.html

I am trying to use the following code in my node-example.tpl.php file.

  echo '<table>';
  foreach ($node->field_features as $delta => $value){
  $term = taxonomy_get_term($node->field_features[$delta]['value']);
  $term_name = check_plain($term->name);
  }
    
  // Default # of Columns
  $numcols = 2;

  // Number of Items
  $numitems = count($term_name);

  // Number of Rows
  $numrows = ceil($numitems/$numcols);

    
    for ($row=1; $row <= $numrows; $row++)
    {
        $cell = 0;
        echo ' <tr>'."\n";
        for ($col=1; $col <= $numcols; $col++)
        {
        echo '  <td>'."\n";

        if ($col===1)
        {
            $cell += $row;
            print $term_name[$cell - 1];
        }
        else {
            $cell += $numrows;
            print $term_name[$cell - 1];
        }
        echo '  </td>'."\n";
        }
        echo ' </tr>'."\n";
    }
    
  echo '</table>';
  

Comments

jdm843’s picture

Ok, got this to work using the following code.

<?php
  echo '<table>';
  
  $items = array();
  foreach ($node->field_features as $delta => $value)
  {
  $term = taxonomy_get_term($node->field_features[$delta]['value']);
  $term_name = check_plain($term->name);
  $items[] = $term_name;
  }

  // Default # of Columns
  $numcols = 2;

  // Number of Items
  $numitems = count($items);//print $numitems;

  // Number of Rows
  $numrows = ceil($numitems/$numcols);//print $numrows;

    
    for ($row=1; $row <= $numrows; $row++)
    {
        $cell = 0;
        echo ' <tr>'."\n";
        for ($col=1; $col <= $numcols; $col++)
        {
        echo '  <td>'."\n";

        if ($col===1)
        {
            $cell += $row;
            print $items[$cell - 1];
        }
        else {
            $cell += $numrows;
            print $items[$cell - 1];
        }
        echo '  </td>'."\n";
        }
        echo ' </tr>'."\n";
    }
    
  echo '</table>';
  
  ?>