Drupal 7

create a custom rule action in drupal7

<?php
  /**
   * Implements hook_rules_action_info().
   */
  function mysite_rules_action_info() {
    return array(
      'mysite_action_foo' => array(
        'label' => t('Klaatu Barata Necktie'),
        'group' => t('Silly Rules Examples'),
      ),
    );
  }

  /**
   * Rule action foo.
   */
  function mysite_action_foo() {
    drupal_set_message("I'm a foo for you!");
  }
  ?>
 

Add JS file on a certain page on Drupal7.

function yourThemeName_preprocess_page(&$variables) {
  // Is this a node addition page for the specific content type?
  // TODO: Adjust the content type to your needs
  // NOTE: Will only work for the node add form – if you want your js to be
  // included for edit forms as well, you need to enhance the check accordingly
  if (‘node’ == arg(0) && ‘add’ == arg(1) && ‘yourContentType’ == arg(2)) {
      // Add your js file as usual
      drupal_add_js(‘path/to/your/file.js’, ‘theme’);

Drupal Theme Hook Suggestions

Theme hook enables any module or theme to provide suggestions for alternative theme feature or template name suggestions and reorder or remove suggestions.

Drupal 7:

<?php
/**
* Implements hook_preprocess_HOOK() for node templates.
*/
function MYTHEME_preprocess_node(&$variables) {
  $variables['theme_hook_suggestions'][] = 'node__' . 'first';
  $variables['theme_hook_suggestions'][] = 'node__' . 'second';
}

Drupal 8:

<?php
/**
* Implements hook_theme_suggestions_HOOK_alter() for node templates.
*/
function MYTHEME_theme_suggestions_node_alter(array &$suggestions, array $variables) {
  $suggestions[] = 'node__' . 'first';
  $suggestions[] = 'node__' . 'second';
}

 

Add CSS files and JavaScript files at the bottom of a page in Drupal 7

template_preprocess_html() in template.php file. Preprocess variables for html.tpl.php
 

function themename_preprocess_html(&$variables) {

  // Add external file
  drupal_add_css('https://fonts.googleapis.com/css?family=Roboto:400,300,500,700',array('type' => 'external'));

  // Add Javascript file at the bottom of a page
  drupal_add_js('/sites/all/themes/purple/js/bootstrap.min.js', array('type' => 'file', 'scope' => 'footer', 'weight' => 10));

}

 

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]