I'm having a difficult time trying to get the theme_table to work properly. Here is what I'm trying to do:

I have a module that gets all taxonomy terms under a specific vocabulary. I provide each term as a link (using the l() function) to the term's children terms and nodes. Currently, these links are returned in the $page_content variable as a long list of categories like this:

Category 1
Category 2
Category 3
Category 4
Category 5
Category 6
...

I'd like to put these links into a table (no headers, no borders) into a format more like this:

Category 1    Category 4    ... 
Category 2    Category 5    ...
Category 3    Category 6    ...

Can anyone give me some pointers? I've done some searching and read the API, but I've been unsuccessful so far.

Thanks!
Chris

Comments

zbricoleur’s picture

Did you get as far as the comments at the bottom of the API page? They spell it out pretty clearly, I would have thought. If you have read that part, maybe you can be more specific in your question, or provide a sample of the code that is not working for you.

http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_table/6

cwrighta70’s picture

Here is some of my module code. Right now I'm simply trying to get the table to show up at all. When $page_content is printed to the screen, all I get is "Array"...no table.


// Implementation of Drupal's hook_help function
function designs_help($path, $arg) {
    // ...
}

// Implementation of Drupal's hook_perm function
function designs_perm() {
    // ...
}


function designs_category($pid) {
   / ...
    $page_content = '';
    $page_content .= designs_getCategories($pid);
    $page_content .= designs_getNodes($pid);
    return $page_content;
}

function designs_getNodes($pid) {
       / ...
}

function designs_getCategories($pid) {
    define($vid, 6);
    $links = array();
    $query = ''; // Gets taxonomy term names

    $results = db_query($query);
    while($categories = db_fetch_array($results)) {
        $new_pid = $categories['tid'];
        $path = "designs_categories/$new_pid";
        $links[] = l($categories['name'], $path);
    }

    $links['#theme'] = 'designs_theme';
    return $links;
}

function designs_theme() {
    return array(
        'designs_theme' => array(
            'arguments' => array('links'),  
        ),
    );
}

function theme_designs_theme($links) {
    $html = '';
    $headers = array('&nbsp','&nbsp','&nbsp');
    $rows = array();
    foreach ($links as $link) {
        $row = array();
        $row[] = drupal_reder($link);
        $rows[] = $row;
    }
    $html = theme('table', $headers, $rows);
    $html .= drupal_render($links);
    return $html;
}

function designs_getFilepath() {
    // ...
}

function designs_menu() {
    // ...
}
Anonymous’s picture

You have a typo in theme_design_theme:

$row[] = drupal_reder($link);

should be

$row[] = drupal_render($link);

Not sure if that's the cause of the problem though.

You could also simplify your loop a bit and fill in the blank tds:

foreach ($links as $link) {
  $rows[] = array(drupal_render($link), '', '');
}
zbricoleur’s picture

I don't have time to test this now, but try getting rid of fn designs_theme and fn theme_designs_theme and restructuring fn designs_getCategories like so:

function designs_getCategories($pid) {
  define($vid, 6); // !?
  $links = array();
  $query = ''; // Gets taxonomy term names

  $results = db_query($query);
  while($categories = db_fetch_array($results)) {
    $new_pid = $categories['tid'];
    $path = "designs_categories/$new_pid";
    $links[] = l($categories['name'], $path);
  }
  $headers = array(' '); // you're only going to have one column! (unless you get fancy like _isos mentions below)
  $rows = array();
  foreach ($links as $link) {
    unset($row);
    $row[] = $link;
    $rows[] = $row;
  }
  $html = theme('table', $headers, $rows);
  return $html;
}
Anonymous’s picture

I'm afraid that's the holy grail of columnising in CSS...without resorting to CSS3 the only way you can do this is with an ugly loop that works out which column each category should be in and dynamically builds up the rows for the table.

This isn't an issue with theme_table at all, theme_table just takes the rows and columns you've defined and displays them. If you want special ordering you'll need to build the rows up in that special way yourself.