views:

63

answers:

2

I used hook_nodeapi to add my custom field to a type of node

$node->content['my_new_field'] = array(
  '#value' => $content,
);

However the new field is only appeared at the end of the content. Is there anyway for me to select a place for it to display ? e.g: between Title and Body.

For some reason I won't be able to use CCK, I want to do it programmatically. Thanks in advance

+5  A: 

There is something called weight. If you llok at the code from API docs, you'll see how that is supposed to work. Lower numbers appear before higher numbers.

So you could do something like

$node->content['my_new_field'] = array(
   '#value' => $content,
   '#weight' => 5, //play with the values until you are happy with the output
 );
DrColossos
thanks I will try this approach :)
iKid
If you implement CCK's hook_content_extra_fields() you will be able to use CCK's drag-n-drop reordering to override the weight specified here. It's a good trick if you are also using CCK fields for other stuff.
Grayside
Sounds like hes not using CCK though
Kevin
A: 

Couldn't you implement hook_load instead to append the node object with your custom fields:

http://api.drupal.org/api/function/hook_load/6

Then you could theme it however you want in node-customtype.tpl.php. Just a thought.

Kevin
That requires too much works for me I think... I don't want to add a new template just to re-order the field
iKid

related questions