By TGReaver on
Hello there,
I'm looking to add a time stamp to comments which basically reads the following.
Username, 37 seconds ago.
The default code in comment.tpl.php is:
<div class="submitted">
<?php
print t('Submitted by !username on !datetime.',
array('!username' => $author, '!datetime' => $created));
Is it a simple case of replacing !datetime with <?php print $submitted; ?>? I'm having trouble getting this to work. Many thanks for any suggestions.
Comments
Ok. here is what you can
Ok. here is what you can do:
First, remove the following code from your theme:
Now, you can compile the time lapsed from the time of adding that comment like this:
Please the following function either in your template.php file or any of your custom modules if you have one:
Sateesh Nutulapati
Devops Solutions Architect at New Target, Inc.
Thank you for your quick
Thank you for your quick response. I've added the function to my template.php file, is it now just a case of replacing:
With
print localised_date($comment->created);?I suppose you also wanted the
I suppose you also wanted the user name? in that case, you have to add that as well.
with this, you will also have to include the get_username function in your template.php file:
I am not sure if my seniors will agree with this method. but you can try it for now, until someone comes and bashes you and me ;-)
also, check if $comment->created prints the date in the first place... just to make sure it returns the timestamp something like 123434281
Sateesh Nutulapati
Devops Solutions Architect at New Target, Inc.
Hi there, I've added the
Hi there,
I've added the code you provided me with to my template.php file, under comments. (Is this correct?) I also added the following code to my comment.tpl.php file to check if the time stamp would print.
Nothing seems to be printing at all, no errors or anything within my browser. I read through the guides SweeneyTodd kindly directed me to and I understand this process a lot more, it should in theory be working?
of course. what sweeny said
of course. what sweeny said is something that already is working in the forum module... if you are comfortable with that logic, that is more advisable...
Sateesh Nutulapati
Devops Solutions Architect at New Target, Inc.
by the way, i copied that
by the way, i copied that function from the localised_date following link:
http://forum.coppermine-gallery.net/index.php?topic=44280.0
Sateesh Nutulapati
Devops Solutions Architect at New Target, Inc.
Look at the core forum module
Look at the core forum module. They have an example there.
In forum-submitted.tpl.php they just have:
$timeis calculated in the preprocess function (function template_preprocess_forum_submitted in forum.module)You should be able to override your preprocess function in your theme to add a time variable and reference it in your template.
It depends on how much experience you have to how easy it is.
Let me know if you need more help.
D6
Hi, your comment help me out a lot. Here is what I did:
The following applies to D6 (not sure about d7)
So what I wanted was "This comment was posted X hrs and x minutes ago"
1) Set up a $timeago variable to be used in your .tpl.php files.
To do this, first go here: http://drupal.org/node/223430
You need to work out the naming convention for your preprocessor. In my case, I used #9
themeName_preprocessbecause im going to put this code in my template.php file in my custom sub theme.2) In template.php
Replace themeName with the name of your theme.
2.1) Where does
$variables['comment']->timestampcome from?Put the following into your comment.tpl.php
<?php dsm($variables) ?>(must have devel module enabled). Now go to a page on your website where (a small number of) comments have been posted. From there you'll see the variablescomment,node,links, etc. Click on comment and you'll see timestamp.2.2) Where does
format_intervalcome from?http://api.drupal.org/api/drupal/includes--common.inc/function/format_in...
2.3) Where does
time()come from?http://php.net/manual/en/function.time.php
3) In comment.tpl.php
Now you can use the variable $timeago which you just created.
print $timeago;