jQuery: update content every week (or long period of time)
Let me start by saying that I'm not a power-JavaScript/jQuery programmer, I do very basic things with it, yet sometimes things get a little hairy for me, like this one.
My case:
I hav开发者_Go百科e a list of testimonials (around 20) and every week (Mondays) I need to updated them.
My problem:
I update them manually. I mean, I open Dreamweaver, update the jQuery code for the corresponding testimonial number, and upload to server.
What I need:
A way to have this be automated... as best as possible.
HTML of testimonials:
<body>
<div class="quotes-container quote-1">
<div class="quote">Testimonial...</div>
<div class="author">Author</div>
</div>
<div class="quotes-container quote-2">
<div class="quote">Testimonial...</div>
<div class="author">Author</div>
</div>
<div class="quotes-container quote-3">
<div class="quote">Testimonial...</div>
<div class="author">Author</div>
</div>
...
</body>
My jQuery used to change the testimonial:
$(function(){
$('#quotes-wrapper').load('/static-files/testimonials.html div.quote-1');
});
As you can see all I need to do is to manually change div.quote-1 to div.quote-2 or div.quote-3 and so on.
But I know there's got to be a way to have jQuery change these testimonials 'dynamically' every Monday (or Tuesday, or any day I choose for that matter), and not have to keep reminders around to not forget to change the testimonials every Monday.
Any ideas how can this be accomplished?
Thanks in advance.
You could find out the week of year to select the div:
(got the code from http://javascript.about.com/library/blweekyear.htm)
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
$(function(){
var today = new Date();
var weekno = today.getWeek();
$('#quotes-wrapper').load('/static-files/testimonials.html div.quote-'+weekno);
});
精彩评论