Node

Create extra fields on nodes

Use hook_field_extra_fields to use the new fields with the manage display function. The content of the new field is built in hook_node_view.

Show one image on a node teaser

Hook_process_field can be used inside template.php to render only one image on a multiple image field.

The fastest way to get nids in a default no cache situation

In this test case scenario a function was made to show the differences when querying for node ids. Mostly this kind of query is the first step to render nodes in a custom made view. Each query returns the same array of node ids. Execution times are tested by using the Drupal 7 bootstrap timer functions.

Load all nodes by type


  $nids = db_select('node', 'n')
  ->fields('n', array('nid'))
  ->condition('n.type', 'NODE_TYPE')
  ->execute()->fetchCol();
  
  $nodes = node_load_multiple($nids);


 

Add an extra field to a content type display

Hook_node_view() can be used to add the block to the renderable $node->content array.
If the weight/order of the extra field needs to be set on the manage display tabs from your article content type, use hook_field_extra_fields() to tell Drupal about the new field.

Remove the read more and comment links on nodes

MYTHEME_preprocess_node is the best solution as it is a theme adjustement. However, when you're using a default Drupal theme, then instead of hacking core, use hook_node_view_alter(&build) inside a custom module.

Subscribe to RSS - Node