1

I have a content type "Blog entry" which I have overridden the template. (node--blog_entry.tpl.php)

The target is to display the node author's full name (as a link) which will take the user to a page (produced by a view) which shows all the other articles they have written.

In my template file, I have the following code:

 function bootstrap_mysite_preprocess_node(&$vars) {
   $vars['author_name'] = $vars['name'];
   $vars['submitted_dt'] = format_date($vars['node']->created, 'custom', 'jS F Y');
 }

The view that I have created which shows the author's other articles takes the UserID as an argument, so what I need is to display a link which which shows the author's full name, but passes their UserID.

the code I have in my custom content template is:

<div class="author-name">
    WRITTEN BY <a href="/user-posts/<?php print $uid; ?>"> <?php print $author_name; ?></a>
  </div>

But author name is not only the author's username (not their full name) but it is output as a link which is no good for me. I simply want to output the author's full name as plain text.

So, to summarise - What can I use instead of $vars['name']; (which producesa username that links to a profile) that will instead produce some plain text of the user's full name ?

2

Your question doesn't indicate whether you are storing the user's full name anywhere. You can add fields to the user profile (at /admin/config/people/accounts/fields). Suppose you add a firstname field (field_user_fname) and lastname field (field_user_lname), you could then write a custom function in your template file, like this:

function _get_author_name($uid) {
  $wrapper = entity_metadata_wrapper('user', $uid);
  $fname = $wrapper->field_user_fname->value();
  $lname = $wrapper->field_user_lname->value();
  return "$fname $lname";
}

And then, since you already know the UID, you could call the function from your content template:

<div class="author-name">
    WRITTEN BY <a href="/user-posts/<?php print $uid; ?>"> 
    <?php print _get_author_name($uid); ?></a>
  </div>

You could also investigate the Realname module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.