Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts

    Article of the Week Coding

    Hello, I've done a lot of google searching looking for something like this but haven't found it yet. The idea is that i want to have on our website an article of the week, basically an article randomly selected from all of the ones we have that will display on the index page for a week's time, as a way of promoting older stuff that might not otherwise be seen.

    The closest I found was a script for a link of the day, but the link for each day is not randomly chosen.

    Has anyone seen a code for something like that? Basically I'd enter into the code every link from which to be chosen, and at the beginning of every week it would randomly choose one to display for that entire week.

    Thanks for any input or help.

  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,704 Times in 2,680 Posts
    Why do you want it to be random? In that case you will need to use a cookie to store the random article in the user's computer so that the same article will be displayed throughout the whole week.

    It would be simpler (and perhaps more effective) just to display a random article each time the user visited your site.

    If you want every user to see the same article then there is no random element involved.

    This code will display a quotation based on the week number. You can easily adapt it for your requirements. Of course, while you must have 53 "quotations" (links) these can be duplicated, and arranged so as to appear to be random.

    <div id = "quoteOfWeek"></div>
    <script type = "text/javascript">
    Date.prototype.getWeek = function() {
    var onejan = new Date(this.getFullYear(),0,1); // month 0 is January
    return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
    var today = new Date();
    var weekno = today.getWeek(); 
    var Quotation = [];
    Quotation[1] = "Sanity is a golden apple with no shoelaces.";
    Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
    Quotation[3] = "Honesty blurts where deception sneezes.";
    Quotation[4] = "Pastry satisfies where art is unavailable.";
    Quotation[5] = "Delete not, lest you, too, be deleted.";
    Quotation[6] = "O! Youth! What a pain in the backside.";
    Quotation[7] = "Wishes are like goldfish with propellors.";
    Quotation[8] = "Love the river's \"beauty\", but live on a hill.";  // note escape quotes
    Quotation[9] = "Invention is the mother of too many useless toys.";
    Quotation[10] = "Time is of the essence! Comb your hair.";
    // and so on for 53 weeks
    Last edited by Philip M; 11-20-2012 at 02:16 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  3. #3
    New to the CF scene
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts
    The idea is for the same article to be shown to all users for the entire week, but for the article to be chosen at random. If there wasn't an easy solution, we'd just pick one article to put a link to each week...

    And I realize now, looking at your code, the folly of what I'm asking for - the code itself could have no way of remembering which one it randomly picked for the duration of the week. I'd essentially have to have a code that referenced another file on the server that specified which one was picked at random. And that sounds way too crazy for someone who can't code, nor would want to pay so much for someone to make something so trivial to begin with.

    Thanks for your time.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts