Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Tuesday, April 5, 2016

Drupal 7 Add Custom Content Type Body Field


<?php
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['content_type_name']);
?>

Use: php filter and run this code or use devel/php

Thursday, October 29, 2015

Get node title from nid without using node_load($nid) in Drupal

Get node title without using node_load($nid).

function get_node_title($nid) {
  $node_title = db_select('node', 'n')
      ->fields('n',array('title'))
      ->condition('nid',$nid,'=')
      ->execute()
      ->fetchField();
  return $node_title;
}

How to render menu programatically in Drupal 7?

In template.php file you can add the below code:

$menu = menu_tree_output(menu_tree_all_data('main-menu', null, 1));
$variables['menu'] = drupal_render($menu);

Page.tpl.php (render the main menu tree in the page.tpl.php like this.)
<?php print $menu; ?>

menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL)
[https://api.drupal.org/api/drupal/includes!menu.inc/function/menu_tree_all_data/7]