I'm running Drupal 4.5. I'd really like to have visual seperation between the different document types. I'd like the display style for a forum to be different from a story. Has anyone tried this? Is it possible with the current version?

Comments

joe@www.joepilot.net’s picture

You can do this via css and slightly editing the theme you're using. Find the function themename_node($node, $main=0, $page=0). Most the the themes place each node in their own div. For instance, my theme generates the node with this code:

function joepilot_node ($node, $main=0, $page=0) {
  $output  = "<div class=\"node node_$node->type\">\n";

  if (!$page) {
    $output .= " <h2 class=\"title\">". ($main ? l($node->title, "node/$node->nid") : $node->title) ."</h2>\n";
  }

  $output .= " <div class=\"content\">\n";

  if ($main && $node->teaser) {
    $output .= $node->teaser;
....

The line $output = "<div class=\"node node_$node->type\">\n"; defines the div class of the node. Find this line and in the class quotes add node_$node->type, as it shows in my function above.

Then you can add different styles to each node type by having the css classes such as: .node_blog { color: red; }
Hope the helps!

skorch’s picture

That's awesome. Thanks for the info.

kps’s picture

You can also make parts of the page outside just the node display be different depending on the node type. Because theme('node', ...) gets called before theme('page', ...), you can record the node type for later use. For instance:

function foo_node($node, $main=0, $page=0) {
  if ($page) {
    global $foo_nodetype;
    $foo_nodetype = $node->type;
  }
  ...
}

function foo_page($content, $title = NULL, $breadcrumb = NULL) {
  ...
  global $foo_nodetype;
  $output .= "<body class=\"$foo_nodetype\">\n";
  ...
}