I'm trying to print the full name of user instead of the username using theme('username',$name); The full name is displayed but with as a hyperlink (in between <a>..</a>) which links to the user's profile page. I just want theme() to output the full name as plain text. Can anyone help?
Please could you say from where you are trying to print the username.
If you are doing this in the template.php, you can get it say from node_preprocess or page_preprocess using:
print $vars['user']->name;
Or if you are in a .tpl file you can use
<?php print $user->name; ?>
User is a global variable so you can grab all kinds of information from it.
If you want to see the available information try putting this in the template.php, say in page_preprocess function / (hook)
print_r ($vars['user']);
Related
I have a preprocess function:
[MYTHEMENAME]_theme_preprocess_views_view_fields__random_quote__block(&$vars)
and then a template file to render the variables:
views-view--random_quote--block.tpl.php
I can easily set a variable like so:
$vars['bam'] = 'whatever';
and display that in my template file. Now my question is, how do I pass the contents of a field to my template? Something like:
$vars['customer_name'] = 'field_customer_name';
Where 'field_customer_name' is a field in the content type. I have tried using the field api and I am getting nowhere. My view is getting that field and I can see the data in the preview of the view content
I still haven't figure out how to do this, but I ended up using a fields tpl (in this case: views-view-fields--random_quote.tpl.php) so I could format each field like so
<cite><b><?php print strip_tags($fields['field_customer_name']->content); ?></b>
Ok, I figured out how to do it!
$entity = $vars['view']->result[0]->_field_data['nid']['entity'];
$vars['customer_name'] = '$entity->field_customer_name[$entity->language][0]['value'];
Hope this helps someone
I wrote a simple twitter connect plugin which needs to display the 'logged in' user's name in the header after he logs in. The function is working properly but I am unable to display the $user variable in my header or anywhere outside the function even though it is assigned global.
Here is the end of the login function:
$user= $Twitter->get_accountVerify_credentials();
print_r($user);
// show screen name (not real name)
$twitter_user = $user->screen_name;
// show profile image url
$twitter_image = $user->profile_image_url;
I can see that it is successful because the $user gets printed, but when I call it in my header.php file the same way I can an error: Notice: Undefined variable: user
Any suggestions?
As opposed to getting wrapped up in the scope of the variables, I'd write a function to get this information. Something like:
function get_twitter_user_name(){
$user= $Twitter->get_accountVerify_credentials();
return $user->screen_name;
}
Then, in the header, where I want to display the name, I'd call the function like so:
<?php echo get_twitter_user_name(); ?>
Depending on the structure of your code, this may look a little different than what I have here, but hopefully this will give you another way of tackling this problem.
Im using pathauto so user profiles have a clean URL in the format /user/name-name
How can I output the users name as a link to the profile? Ive seen the theme() function used to do stuff similar to this?
Use the l() function to create the link and make the link to user/uid. When using l, it will be converted to whatever you set it up to in pathauto.
If you want the user's name as the text of the link, use theme('username', $account); where $account is the fully-loaded user object from user_load().
I'm a drupal newbie...
<?php print $node->field_date[0]['view']; ?>
I can get the custom created CCK fields' value and display in tpl.php files as above... that's fine.
my question is how can I get the Node reference fields' in-fields? for example, I have an event content type, and I have defined Node Reference for Location (title, address, img, etc.). When I write the code below, it displays all location content;
<?php print $node->field_location[0]['view']; ?>
but I need to get only address field from this location content type. sth like below would be great :D but not working;
<?php print $node->field_location[0]['field_address']['view']; ?>
so how can get that? appreciate helps so much! thanks a lot!
You should inspect/dump the content of the $node->field_location array. I do not have a test installation at hand right now, so I can't say for sure, but I'd expect that at least the referenced nodes id ('nid') should be in that array somewhere. With that, you can do a node_load($nid), which returns the full node object, thus providing access to the fields.
(As said, I'm not sure, but the field array might already contain the whole node object as well, saving you from the need to load it explicitely.)
The $node->field_location[0]['view']; returns the node as it was defined in the Display Fields section of the content type definition. This might work for your advantage. You can trick it: use a Teaser display for that node and customize the node Teaser display to fit your needs. Just a thought.
If that doesn’t work for you, you will need to load the node separately. You can use $node->field_location[0]['nid']; to get the node ID, so you will end up with something like this:
node_load($node->field_location[0]['nid'])->field_address[0]['view']
I'm not sure how this performs...
i need to display the contents added by that user...
i have designed a view to display the result.. but it displays the results of all users.....
i need to display the contents added by that user...
when i pass the argument of userid it works, but is there any dynamic way to do that....
If all you need is a list of nodes by the current user, the easiest way is to use the User:Current filter. Just click the [+] next to 'Filters', choose 'User:Current' from the list, click the 'Add' button and set the filter to 'Yes'.
The argument-method as described by streetparade (using the 'User: Uid' argument) is useful if you want users to see the list of other users as well. Suppose that your view's url is www.example.com/my-content. If you add a user argument, user #3 could see what user #7 has posted on www.example.com/my-content/7. If you want that, use the argument. If you do not want that, use the filter.
Use This
<?php
global $user;
$userId = $user->uid;
?>
You can access all this way
(source: chromaticsites.com)