Monday, 3 October 2011

simple drupal "hello world" block custom modules


this is just a really fast and crude way to printout the content in creating a drupal custom modules

 module name "hello_world"

first step is to create a "info" file for your modules ""

and paste in the before code

 ; $Id$  
 name = hello_world  
 description = Custom functions for this site.  
 core = 6.x  

next step is to create a module file this is the file where all the logic goes
create a file "hello_world.module" and paste in the below code

 // $Id: hello_world.module  
 * @file* Custom functions for this site.  
  //implementing the hook_block functions   
 function hello_world_block($op = 'list',$delta = 0, $edit =array()){  
 if($op == 'list'){ //listing the blocks  
 'info'=> t('hello world block'),  
 'weight' => 0,  
 return $blocks;  
 //loading the content of the blocks   
 if($op == 'view'){  
 if($delta == 0){  
 $blocks = array(  
 'subject' => t('hello world blocks'),  
 'content' => '<h1>hello world</h1>';// alternatively you can call a function which return the data  
 return $blocks;  

this above code can be used to quickly create block to display a banner or ad-script in a block or a even iframe.

Sunday, 2 October 2011

author information in a drupal block


here is simple php snippet used to show the author picture and name in a block .

ok this is how this works it collect the node-nid from the url. load's the node get the author uid and then load the user and print the information about the user

 //url example{nid}  
 if(isnumeric(arg(1)){ //  
 $node=node_load(arg(1)); // using the node load function  
 if($node){ // checking whether node object is loaded  
 $author = user_load($node->uid);//using the user load function to load the user object  
 echo '<div>';  
 echo '<img src="'.$author->picture.'" /><br/>'; // print the path to the user iamge  
 echo '<b>'.$author->name.'</b><br/>'; //print the user name  
 echo '<b>'.$author->mail.'</b><br/>'; // print the email address of the user  
 echo '</div>';  

this might be very crude way of doing this. alternatively you can create view to do the same