Forum Moderators: mack
For example if a site is updated with a fresh new article you would see...posted 1 minute ago and if you would return 3 days later you would see.....72 hours and 5 minutes ago.
I think you know what i mean, it is something that is widely used and would also like to have this kind of feature on my site but don't know how to do this or what kind of script i need to use for this, don't even know how such a script is called.
Hope somebody knows how i can do this?
Thanks in advance guys.
easy enough to do though as MichaelBluejay mentioned it depends on how they are posted. You would need a date and time attributed to the post/article itself and then compare that with the present time. If you use a scripting language of some sort now any of them can handle this. It isn't a script unto itself it would be a small feature of one.
Now i know and correct me if i am wrong that i need a client and a server side script for making this possible.
What would be the best script language to use regarding my inexpierence with script languages?
I have a piece of javascript that i could include in my website page itself, the client side so to speak but i need another sort of script language to make it combine with each other right?
The following is the javascript that i have found:
<script language="javascript">
function difference(oldtime) {
var nowtime = new Date();
var milliseconds1 = oldtime.getTime();
var milliseconds2 = nowtime.getTime();
var difference = milliseconds2 - milliseconds1;
var daysDifference = Math.floor(difference/1000/60/60/24);
difference = difference - daysDifference*1000*60*60*24
var hoursDifference = Math.floor(difference/1000/60/60);
difference = difference - hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference = difference - minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);
// This next line below looks for entries over a day old
if (daysDifference > 1) document.write('  \;<span class="lastupdated"><b>' + daysDifference + '</b> days, <b>' + hoursDifference + '</b> hours,<b> ' + minutesDifference + '</b> minutes ago</span>');
else if (hoursDifference < 1) document.write('  \;<span class="lastupdated"><b>' + minutesDifference + ' </b> minutes ago</span>');
else if (hoursDifference < 4) document.write('  \;<span class="lastupdated"><b>' + hoursDifference + ' </b> hours, <b> ' + minutesDifference + ' </b> minutes ago</span>');
else if (hoursDifference < 24) document.write('  \;<span class="lastupdated"><b>' + hoursDifference + ' </b> hours ago</span>');
else document.write(' ');
}
</script>
And this is the php script that i can use for the server side that somebody put together for me:
<?
function elapsed_time ( $start, $end )
{
$diff = $end - $start;
$days = floor ( $diff/86400 ); //calculate the days
$diff = $diff - ($days*86400); // subtract the days
$hours = floor ( $diff/3600 ); // calculate the hours
$diff = $diff - ($hours*3600); // subtract the hours
$mins = floor ( $diff/60 ); // calculate the minutes
$diff = $diff - ($mins*60); // subtract the mins
$secs = $diff; // what's left is the seconds;
return "Article was posted ".$days." days, ".$hours." hours, ".$mins." minutes and ".$secs." seconds ago.";
}
$post = 1121642445; // this would be the time stamp you get back from the database
$now = mktime(); // time now
echo elapsed_time ( $post, $now );
?>
I am very confused if these codes are correct and on how to implement them to make everything work in the manor i expect.
If i make a change on the page in question that has articles being placed on, would the javascript and php script above combined work to display a "posted ago" message with the brief description of the content of the article.
And how do i add other content without displaying the "posted ago" message?
Because at this point to my knowledge if i implement these scripts then everything that i add will contain a "posted ago" message, and i only want the message display for the news articles.
I am planning to use a piece of software that i can use for adding articles and the brief article descriptions on the home page, it works by e-mail, i can add new content by just sending a e-mail and then the content is being placed on the website, if the software does what is says:) that is, i have not tried it out yet but will see if this works for me.
---------
<HTML><HEAD>
<script type="text/javascript">
function printElapsedTime(startingDate) {
(code to figure the elapsed time goes here)
document.write('Posted ' + elapsedTime + ' days ago');
}
</script>
</HEAD>
<BODY>
<P>blah blah blah
<script type="text/javascript">printElapsedTime('7-20-05')</script>
<P>blah blah blah
</BODY>
</HTML> When you post a new article, just change the '7-20-05' to the date of your choice.
Preferably you should also put the printElapsedTime function in a separate file.
If you need more help I'd take this to the Javascript forum.
Seperate file? How do i do this?
Also when posting a new article, i don't understand how i can make this work for every article that is going to be placed?, How do i merge the article and the script together so the script can do it's job?
I have a lot of questions, and i think with every answer i have a question, i really hope you don't mind?
I'm glad somebody is helping me out on this!
I can understand if you are busy but hope someone else can jump in someday and also offcourse you have the time someday to discuss this with me:)
Installing everything, learning how to update via database and then installing scripts, if i want to do this, i can maybe start next year putting the site online , sounds like i am really thinking i am over my head with PHP, doesn't it?, your right i do feel like this:)
All those command strings are scaring the **** out of me:(
It all sounds very complicated, therefor i thought javascript sounds like a good option:)
but do i care? no not really
You should care if you care about your site visitors
most people i guess have javascript turned on.
They key phrase being "i guess". Many corporations, businesses, schools, etc. have network administrators that force their users to turn off javascript. That could cause issues if you wanted anyone to navigate your website from their place of work.
Like i mentioned, it's for the time ago posted message that i would like to combine with the articles, nothing more:) but i do understand your point, that you have to take in considderation all kind off possibilities that would cause the main function of a website to fail, so you can anticipate on it, but this doesn't count for me apart from the posted ago message with the articles.
But would not cause problems for the visitor, you see i do care about the visitors, afterall this is what it makes worth while, the only thing is my problem with PHP, therefor i choose to have a simpler option and in due time maybe i can look into the option for someone to help me out with this, some sort of agency?
Yes, i followed your advice but no one seems to know how to do this or want to reply to my post in the javascript section, i did give it a new title "something nice to add to a news article"
Wow, and you actually thought that was helpful? Here's a rule of thumb: If some has to OPEN your post before they have a clue as to what it's about, then it's got a bad title. Really, that's just one step above the completely useless "please help" and "question". It's at about the same level as the slightly less useless "question about [some topic]".
You should care if you care about your site visitors
This is just ridiculous. As though you're punishing the <1% of visitors if they don't see some extra text that they wouldn't see anyway had you not installed the Last Updated script. As though you should bend over backwards to learn server-side scripting just so a tiny tiny tiny tiny minority of users can have access to what's a superfluous feature anyway.
Worry about Javascript whe the lack of it would BREAK your site, not when it effectively makes NO IMPORTANT DIFFERENCE WHATSOEVER.
The other thing is that often those who preach about catering to the 1% of visitors are quite happy to punish the other 99%. I design dynamic E-commerce sites that make browsing and ordering products a breeze for the 99% of users with Javascript -- a much better experience than they'd get on typical sites. The 1% of the users without Javascript don't get those features. Many purists wouldn't design my style of site because it punishes 1% of visitors, although NOT designing a nice dynamic site punishes 99% of them.
If it's easy for you to add a feature that enhances the experience of 99% of your visitors, do you do so, or do you hold out on them just because that feature won't work for everyone? This should be no contest.
Okay, Krez, you asked about how to put Javascript in a separate file. Just put all the Javascript code in a text file, say "javascript.js", and pull it into your HTML document like so:
<HTML><HEAD>
<SCRIPT type=text/javascript src="javascript.js"></SCRIPT>
</HEAD>
That keeps your HTML document nice and tidy. Also, if you need to change your Javascript code later on, you can change it in one place, rather than having to update a script that's hard-coded into every page.
In your text file just have the functions themselves; don't include the <SCRIPT></SCRIPT> tags in the text file.
As to how to make it work for every article placed, in msg#5 I showed you the rough outline. Every time you post an article, you'll need to update the date that's listed. In my example it says 7-20-05. Change as necessary.