easy as pie. Open your node.tpl.php file for the theme you're using. Somewhere it will have a line in php brackets that says <?php print $submitted ?>. Change that to print $name and you're set. If you want the date somewhere else, you can get it using print $date .
To understand which variables are available to your node, open up the phptemplate.engine file and find the function called phptemplate_node, around line 266. You'll see a big array. You can get anything there to show up on your page by simply using print $variable_name in node.tpl.php. (Where $variable_name is the left side of one of the array pairs in phptemplate_node that look like this: 'variable_name' => a_drupal_function($input) or $a_variable, )
Thanks for that answer... I've been wondering about this as well. I looked into this a while back and I bailed out of node.tpl.php when I saw it using $submitted, which has the full string. I didn't know where else to look for the array with $name & $date (among others).
That's one of those drupal things with many different solutions.
In phptemplate.engine the function phptemplate_node has that big array called $vars. There's a line that looks like this:
'date' => format_date($node->created),
You can change that to format_date($node->created, 'small') or ... ($node->created, 'large') to use the format that you've set on the admin settings page. Or it's very easy to write your own custom format. It would look (for example) like this: format_date('custom', 'm/d/Y'). This second parameter here is the key (in my example, 'm/d/Y' would give dates that look like 12/25/2006) - go to http://php.net/date to learn all of your month, day, year etc options.
When I changed the variable from $submitted to $name it did drop the date, but it also dropped the "Submitted by" text and it also cause the authors name to display on content types that had been set not to display the "Submitted by" info. How does a person fix those two side effects?
Ok, shouldn't be too hard. If you want everything to obey those "submitted by" settings, the quickest way to fix this will involve a tiny hack in the phptemplate.engine file. It's easy, but as a tip - make sure you make a note to yourself that you're altering the file.
Open phptemplate.engine in any code or text editor (You'll find it under themes/engines/phptemplate in your drupal directory). Find a function called phptemplate_node (somewhere between lines 250 and 300, depending on whether you're using 4.6 or 4.7). Look for this line:
$vars['submitted'] = t('Submitted by %a on %b.', array('%a' => format_name($node), '%b' => format_date($node->created)));.
All you really have to do is cut out the part that says "on %b". In other words, change the line so it looks like this: $vars['submitted'] = t('Submitted by %a.', array('%a' => format_name($node), '%b' => format_date($node->created)));. As you can probably see, drupal is replacing %a and %b with the contents of that array.
Now that you're in this function, you can tinker with other things - like putting 'Written by %a.' or '%a created this.' or whatever you wish.
If you're positive you'll never want date/time included in the Submitted by string, you can go a step further. The first solution above stops the date/time from being displayed, but not from being (harmlessly) generated. Doing this:$vars['submitted'] = t('Submitted by %a.', array('%a' => format_name($node))); wipes the date/time string completely.
<?php if ($submitted) { ?><span class="submitted">Submitted by <?php print $name?> on <?php print date("l, jS F Y", strtotime($date))?></span><?php }; ?>
With a little bit of thought, this can be adapted to suit all of the needs mentioned in this thread.
Add or remove bits as necessary, or change the date format 'l, jS F Y' using the options given at http://php.net/date.
wow... you know I was banging my head against the wall trying to figure out that... it really begs to ask, why isn't that the default code in the first place!
Comments
easy as pie. Open your
easy as pie. Open your node.tpl.php file for the theme you're using. Somewhere it will have a line in php brackets that says
<?php print $submitted ?>. Change that toprint $nameand you're set. If you want the date somewhere else, you can get it usingprint $date.To understand which variables are available to your node, open up the phptemplate.engine file and find the function called phptemplate_node, around line 266. You'll see a big array. You can get anything there to show up on your page by simply using print $variable_name in node.tpl.php. (Where $variable_name is the left side of one of the array pairs in phptemplate_node that look like this:
'variable_name' => a_drupal_function($input) or $a_variable,)Thanks for the slice...
Thanks for that answer... I've been wondering about this as well. I looked into this a while back and I bailed out of node.tpl.php when I saw it using $submitted, which has the full string. I didn't know where else to look for the array with $name & $date (among others).
Wonderful stuff!
thanks..
but how to change data format? thanks
many ways to change date format
That's one of those drupal things with many different solutions.
In phptemplate.engine the function phptemplate_node has that big array called $vars. There's a line that looks like this:
'date' => format_date($node->created),You can change that to format_date($node->created, 'small') or ... ($node->created, 'large') to use the format that you've set on the admin settings page. Or it's very easy to write your own custom format. It would look (for example) like this: format_date('custom', 'm/d/Y'). This second parameter here is the key (in my example, 'm/d/Y' would give dates that look like 12/25/2006) - go to http://php.net/date to learn all of your month, day, year etc options.
something is still not right..
hi,
i tried it, but i still can't get it display correctly. the date format is still the old one :Mon, 2006-04-17 03:55.
"Submitted by" display options affected
When I changed the variable from $submitted to $name it did drop the date, but it also dropped the "Submitted by" text and it also cause the authors name to display on content types that had been set not to display the "Submitted by" info. How does a person fix those two side effects?
Roger
dig into phptemplate.engine to fine tune submitted by options
Ok, shouldn't be too hard. If you want everything to obey those "submitted by" settings, the quickest way to fix this will involve a tiny hack in the phptemplate.engine file. It's easy, but as a tip - make sure you make a note to yourself that you're altering the file.
Open phptemplate.engine in any code or text editor (You'll find it under themes/engines/phptemplate in your drupal directory). Find a function called phptemplate_node (somewhere between lines 250 and 300, depending on whether you're using 4.6 or 4.7). Look for this line:
$vars['submitted'] = t('Submitted by %a on %b.', array('%a' => format_name($node), '%b' => format_date($node->created)));.All you really have to do is cut out the part that says "on %b". In other words, change the line so it looks like this:
$vars['submitted'] = t('Submitted by %a.', array('%a' => format_name($node), '%b' => format_date($node->created)));. As you can probably see, drupal is replacing %a and %b with the contents of that array.Now that you're in this function, you can tinker with other things - like putting 'Written by %a.' or '%a created this.' or whatever you wish.
If you're positive you'll never want date/time included in the Submitted by string, you can go a step further. The first solution above stops the date/time from being displayed, but not from being (harmlessly) generated. Doing this:
$vars['submitted'] = t('Submitted by %a.', array('%a' => format_name($node)));wipes the date/time string completely.Hope this helps.
How I Do It...
In my *.tpl.php files I replace this code...
With this...
With a little bit of thought, this can be adapted to suit all of the needs mentioned in this thread.
Add or remove bits as necessary, or change the date format 'l, jS F Y' using the options given at http://php.net/date.
custom submitted code
wow... you know I was banging my head against the wall trying to figure out that... it really begs to ask, why isn't that the default code in the first place!
thanks Sverre!