Skip to main content

Override "Submitted by" in a fusion subtheme

Recently i was asked to replace the username in the "submitted by" section with the user's first name and last name ( assuming that there are profile fields named "last_name" and "first_name" and  the fields are created with the profile module . This of course does not mean that you cant use the content profile module  as  an alternative but you would  have to replace the profile variable fields with the content profile variable fields  ). So if for example your userame is "superman" and you create a new blog post then the username 'superman' would be replaced by the  last_name and first_name of the profile  fields . So superman is  "Clark Kent" now :) . . .

So how do we ovveride this ?

The solution to this problem is to add at our template.php file the mytheme_preprocess_node function  and then replace  the vars we want with the profile fields . So since i am using the fusion theming system and my subtheme is the superheroes theme , i should create a template.php file inside my fusion subtheme folder  and add  there my overrides . So my fusion directory structure is like this now :  fusion/subtheme/template.php and if my fusion subtheme name is superheroes then my path is :  sites/all/themes/fusion/superheroes/template.php . ( Please notice that it's template.php and not template.tpl.php ) .

@date by !first !last', array( '!first' => user_load(array('uid' => $vars['node']->uid, 'status' => 1))->profile_firstname, '!last' => user_load(array('uid' => $vars['node']->uid, 'status' => 1))->profile_lastname, '!username' => theme('username', $vars['node']), '@date' => format_date($vars['node']->created,'custom', "F jS, Y"), '!microdate' => format_date($vars['node']->created,'custom', "Y-m-d\TH:i:sO") ) ); } ?>

And how about the comments ?

Basically it's the same with a few variable name changes.

@date by !first !last', array( '!first' => user_load(array('uid' => $vars['comment']->uid, 'status' => 1))->profile_firstname, '!last' => user_load(array('uid' => $vars['comment']->uid, 'status' => 1))->profile_lastname, '!username' => theme('username', $vars['comment']), '@date' => format_date($vars['comment']->timestamp,'custom', "F jS, Y"), '!microdate' => format_date($vars['comment']->timestamp,'custom', "Y-m-d\TH:i:sO") ) ); } ?>