How to move the Node Body into a CCK Field Group

This code snippet will put the node body into a CCK Field Group for selected node types.

You will need to create the following files.

mymodule.info

name = My Module
package = My Module
description = My module override functions.
version = "5.x-1"
project = "mymodule"

mymodule.module

 function mymodule_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  // move body into group_details in teaser
  $types = array('blog'=>'group_details','story'=>'group_details');
  foreach($types as $type=>$field_group) {
    if ($op=='view' && $node->type==$type && $teaser && isset($node->content[$field_group])) {
      $node->content[$field_group]['body'] = $node->content['body'];
      unset($node->content['body']);
      break;
    }
  }
}

You will have to change this code: $types = array('story'=>'group_details','book'=>'group_information');

The format is $types = array('[NODE TYPE]'=>'[FIELD GROUP]'); where [NODE TYPE] is the type of node and [FIELD GROUP] is the name of the field group where the body will be moved to.

Upload these files to sites/all/modules/mymodule

Go to Admin > Site Building > Modules and enable your new module.

Post new comment

  • Allowed HTML tags: <b> <br> <p> <a> <strong> <cite> <em> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You may use [img:xx] tags to display uploaded files or images inline.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <css>, <diff>, <drupal5>, <html>, <javascript>, <php>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options