Sunday 2 October 2011

author information in a drupal block



hi

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


 <?php  
 //url example http://domain.com/node/{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

No comments:

Post a Comment