Monday, January 31, 2011

how to create menu using custom module Drupal 6

Suppose your custom module name is xyz.
function xyz_perm() {

  return array(‘Access My menu’);

}

function xyz_menu()

{

   $items=array();

      $items['mymenu] = array(

      'title' => t(‘My Menu’),

      'page callback' => ‘xyz_mymenu’,

      'access arguments' => array('Access My menu'),

      'type' => MENU_CALLBACK,

             

  );

  return $items;

}

function xyz_mymenu (){

…… WRITE YOUR CODE HERE ……

}

How to create a block using module in Drupal 6.



Custom Drupal module | Code for building block using Drupal custom module
By using this piece of code you can easily create a block that can display anything. If you want to show data for a particular content  type or anything from database this code will be very helpful for that.

Suppose your custom module name is xyz.
<?php
function xyz_block($op='list', $delta=0, $edit = array())
{

    if( $op == 'list' ) {
             $block[0]['info'] = "Test";
                         
             
    } else if ( $op == 'view' ) {
            switch($delta) 
            {
                 case 0:
                         $block['subject'] =  "Test";
                         $block['content'] =  xyz_Services();
                         break;
            }
     }
                         
     return $block;
}


function xyz_Services()
{  
    … PUT YOUR CODE HERE  FOR OUTPUT [BLOCK CONTENT]…
}
?>

Code for Taxonomy in Drupal 7


Taxonomy allows users to add terms to content. The taxonomy for a site contains one or more vocabularies and each vocabulary contains a set of terms. In Drupal 7 settings for taxonomy module can be found at Administer > Structure > Taxonomy. The Taxonomy module organizes taxonomies into vocabularies which consist of one or more terms. Each vocabulary consists of a set of terms.

This piece of code will display the  terms.

<?php if ($terms): ?>
     <div class="terms"><?php print $terms ?></div>
<?php endif;?>

Code for Primary and Secondary menu in Drupal 7


<div id="menu">
    <?php if (isset($secondary_menu)) { ?><?php print theme('links', $secondary_menu, array('class' => 'links', 'id' => 'subnavlist')); ?><?php } ?>
    <?php if (isset($main_menu)) { ?><?php print theme('links', $main_menu, array('class' => 'links', 'id' => 'navlist')) ?><?php } ?>
  </div>

For more information please visit:

How to Attach JavaScript and CSS for drupal_render in Drupal 7


<?php
function example_admin_settings() {
 
$form['#attached_css'] = array(
    drupal_get_path('module', 'example') . '/example.admin.css'
 
),
 
$form['#attached_js'] = array(
    'alert("Hello World.");' => 'inline',
    array(
     
'data' => array('mymodule' => array(...)),
     
'type' => 'setting'
   
),
  );
 
$form['example'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Example');
  );
  return
$form;
}
?>

For more please visit:

Saturday, January 29, 2011

How to Theme a block in Drupal 7


For theming a block  you need to create a page named “block--blockname.tpl.php” into sites/all/themes/yourtheme folder.

How to Theme a region in Drupal 7


For theming a region you need to create a page named “region--regionname.tpl.php” into sites/all/themes/yourtheme folder.