Move the Node Body into a CCK Field Group in Drupal

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

<?php 
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.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <i> <strong> <cite> <em> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <css>, <diff>, <drupal5>, <html>, <javascript>, <php>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.