I created file node--my_content_type.tpl.php, where I'd like to print the username as string. I tried the following code, but unfortunately it doesn't work. How can I do it?
<?php print $name; ?>
$node->name will get you the name of the author who submitted the node. It will return it as string, not as link to the user account.
Usernames are stored in the
global $user; print_r($user);
If you mean the fields in a node, those would be in the node object (
I highly recommend looking at the output of the above. Get familiar with both the user object and the node object and everything will make a lot more sense.
$user = user_load($node->uid); print $user->name;
This way you can get the name of author by loading the user.