Last updated August 10, 2012. Created by tax14 on February 25, 2011.
Edited by brankoc. Log in to edit this page.
When you create an article or page in Drupal 7, by default, it displays Author and Date information after the title, something like:
published by admin on Thu, 02/17/2011 - 11:08
If you don't want to see this information, disable the Display Settings option for the corresponding content type with these steps:
1. Log-in as Admin and choose Structure, Content types and click edit (under Operations) for the corresponding content type (e.g. Article).
2. Click Display Settings and un-check Display author and date information check box.
3. Save settings by clicking the Save Content Type button.
Now, the author and date information will not be displayed for the corresponding content type.
How about if you want to display the date information but not the author information, e.g. you want to see something like:
Posted: February 23, 2011
To accomplish this,
1. Enable Display Settings for the corresponding content type.
2. Edit the node.tpl.php file of the corresponding theme you are using, e.g. themes\bartik\templates\node.tpl.php and located the following command:print $submitted;
3. Now replace this command with the following code: // print $submitted;
if ($submitted) {
echo "Posted: " . date( "F j, Y",$node->created);
}
4. Save the file and you should see the submitted information in the desired format. Of course, you can use a different date format or add additional node details.
Modules
Modules that let you perform the operations above without programming skills:
- Submitted By (the D7 version is under development, but is already usable - check the Issue list for known quirks)
Comments
When you need that date in other languages
If you need to format the dates with an specific language you can't use the format_date function provided by Drupal. (http://api.drupal.org/api/drupal/includes--common.inc/function/format_date)
In my case I use a code likes:
format_date($node->created, $type = 'medium', $format = 'F j - Y', $timezone = NULL, $langcode = 'es')I hope that it will be helpful for developers in Latam or other countries.
authoring information
After i am adding some content and in authoring information adding time , it automatically sets to am.. i want to have it in pm, manually.. can you plz help??
himani
Another option is to use
Another option is to use hook_preprocess_node in your template.php file:
<?phpTHEME_preprocess_node(&$variables) {
if ($variables['submitted']) {
$variables['submitted'] = t('Posted: !datetime', array( '!datetime' => format_date($variables['node']->created, 'custom', 'F j, Y')));
}
}
?>
This provides a much cleaner override of the submitted variable for nodes.
Wondering aloud - why doesn't
Wondering aloud - why doesn't "display settings" have two check boxes - one for Author and one for Date - after all they start off as two fields.
peter davis : fuzion : connect.campaign.communicate : www.fuzion.co.nz
+1. Also seems like these
+1. Also seems like these checkboxes should be on the Manage Display page (admin/structure/types/manage/page/display) instead of the Edit page.
Albatross Digital
Full-service Drupal development and design
www.albatrossdigital.com
+1
Yes, on the manage display page and as two separate checkboxes and with a dropdown to select the different formats please, that would make way more sense and be really flexible.
+1
Agreed. It seems nonsensical to combine these fields.
Mike
--
http://noseyparka.me.uk/ - I build web sites and teach people how to build web sites.
+1
it would be a nice usability improvement
--
fabio weblapkészítés
Display Suite
btw I just came across the Display Suite module which changes the "manage display" page to allow exactly for that and moving title, links, comments and way more useful features like changing/resetting field and views templates, linking between displays, dynamic & block fields, moving fields to a block just to name a few. Imho could replace views in those cases where you mainly use views to have more control over the output...
Thank you for information :)
Thank you for information :)
and for author only ?
Can i ask what the code would be to get author only instead of date ?
something like that, i presume :
if ($submitted) {echo "Author: " . ???( "???",$node->created);
}
but what about "???"
CC
suppress author or date in "Posted*: " * (*not in english !)
i answer to myself : there is nothing easier ... when you are using another language !!!
you go in site building / translate interface / search
and you search :
string contains : -->"Posted*" (* the translated term in the other language you use)
in "Built-in interface" you find your text
you edit and you find :
"Submitted by !username on @datetime" (translated)
you suppress the one you don't want anymore, register : it's ready !
CC
Specific content type settings
Hey there!
I don't understand how I can change that for a specific custom content type. What's the corresponding file name? Let's say my content type is called "mynews".
Thanks
~Eduardo~
got it
I did it with CSS by using a new style for the content type's class. I tried Display Suite but couldn't find a the place to configure the author/date for my custom content type. Anyway, maybe I'll try it later with Panels...
~Eduardo~
Template for a specific content type
In your theme, you need to make a copy of node.tpl.php. Then rename this file node--your-content-type-machine-name.tpl.php. So in your case, the new file would be named node--mynews.tpl.php.
Detailed explanation
Here's a detailed explanation of customizing the "Submitted by [name] on [date]" string.
There are two places you can modify this string:
1 ) Inside of
template.phpin your theme, edit (or add) the following function:<?phpfunction THEMENAME_preprocess_node(&$variables) {
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
}
?>
Or you can modify
node.tpl.phpand change the$submittedvariable:<?php$submitted = t('Submitted by !username on !datetime', array('!username' => $name, '!datetime' => $date));
?>
You can customize those parts to change the wording "Submitted by", or only display the username or date. The following examples are using the
template.phpapproach. For thenode.tpl.phpformat, you would change$variables['myvariablename']to$myvariablename.If you only want the username:
<?php$variables['submitted'] = t('Submitted by !username', array('!username' => $variables['name']));
?>
And only the date:
<?php$variables['submitted'] = t('Submitted on !datetime', array('!datetime' => $variables['date']));
?>
(and of course you can change the string "Submitted on" to whatever you like.)
To customize the date format, the recommended solution is to use one of the predefined formats under
Configuration > Regional and Language > Date and Time(Drupal 7.x) orSite Configuration > Date and Time(Drupal 6.x). Once this is done, you can then use those predefined formats in your code withformat_date(). Refer to the Drupal API for full details on the format_date() function.To use one of the formats that you set up above:
<?php$variables['date'] = format_date($variables['node']->created, 'format_type'));
// Where 'format_type' is one of: 'long', 'medium' or 'short'
?>
You can also use 'custom' as the format type, and specify your own format in the third parameter:
<?php$variables['date'] = format_date($variables['node']->created, 'custom', 'F j, Y');
?>
The third parameter is a combination of date parts. You can view a full list here: http://www.b2ben.com/php/phpdate.php or http://www.php.net/manual/en/function.date.php
~ Digital Cowboy Extraordinaire ~
little error
A little error has made her way thru copy&paste functionality:
<?php$variables['date'] = format_date($variables['node']->created, 'format_type');
// Where 'format_type' is one of: 'long', 'medium' or 'short'
?>
only 1 parenthesis at the end...
But still a big thank to @hargobind for the detailed explanation !
David
http://www.smol.org
newbie solution maybe
I edited the theme template.php (just to remind me) from drupal root ./sites/all/themes/"theme name"/
I added selfcreated time format named suomilyhyt using Drupal 7 admin panels as noted before
// Muokataan päiväformaatti vastaamaan suomi asetuksia.
$variables['date'] = format_date($variables['node']->created, 'suomilyhyt');
// Add pubdate to submitted variable.
$variables['pubdate'] = 'created, 'custom', 'c') . '">' . $variables['date'] . '';
if ($variables['display_submitted']) {
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['pubdate']));
}
Worked for me just fine. I am a little bit rust on php and so on. I am not sure about possible error handling if variable date is not set but I have to start learning from some where.
Thanks a lot for solution. :)
Learning to get a job.
petrieskelinen.info
+1
So glad it was this easy! :D Thanks a bunch
Drupal 6
How to Control/Modify Display Settings (Author and Date Information) on Posts
Does anyone know how to do this in Drupal 6?
Diana
Drupal 6
You can use the MYTHEMENAME_preprocess_node function in template.php also in drupal 6. Maybe the way to alter the $variables['submitted'] will be slightly different.
David
http://www.smol.org