SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Automatically changing content once a week

    I am trying to save some time by updating text (articles) on a website once a week. I'm not too familiar with server-side scripting, so, I figured this would not be too difficult with Javascript. I'm sure this can be done with variables but, how can I change just the content within the same page? Or, do I have to load a different version of the page (based upon the week number) for each week? Any insight would be greatly appreciated!

  2. #2
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    what i would do is...

    load an extrenal javascript within another javascript.

    The external javascript will be our up-to-date content.

    for example:

    Code:
    <script type="text/javascript" src="" id="loader"></script>
    <script type="text/javascript">
    var loaderSrc="http://www.somesite.com/loader.js&"+Date.parse(Date());
    function loadContent(){
      document.getElementById('loader').src=loaderSrc;
    }
    </script>
    <body onload="loadContent()">
    <div id="content">
    
    </div>
    </body>
    then in the external javascript use something like:
    Code:
    var content = document.getElementById('content');
    content.innerHTML = "now you can put anything here... just update this once a week and you are good to go.. BTW this also supports <b>HTML</b>";
    Then all you have to do is change that one file every week to use your new content,
    -ALL
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site

  3. #3
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting! It seems, I still have to update once a week as opposed to having it done, automatically. I may not be the webmaster for this site and would like to have the text articles appear relative to a particular day of the week and filename. Am I missing this in your suggestion?

  4. #4
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh, so you have 7 articles and want to rotate them?

    simple enough...

    Code:
    var d=new Date()
    var weekday=new Array(7)
    weekday[0]="Sunday"
    weekday[1]="Monday"
    weekday[2]="Tuesday"
    weekday[3]="Wednesday"
    weekday[4]="Thursday"
    weekday[5]="Friday"
    weekday[6]="Saturday"
    
    var loaderSrc="http://www.somesite.com/"+weekday[d.getDay()]+".js");
    function loadContent(){
      document.getElementById('loader').src=loaderSrc;
    }
    Then just make Monday.js, Tuesday.js, exc... and use the stuff i said above...
    but as you may know... javascript isnt very searchengine friendly,
    -ALL
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site

  5. #5
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! That's the idea except the rotation is once a week. So, the var would have to extract the week number, as opposed to, the day of the week. That would mean 52 .js files, on top of the 52 content files. This is what I was hoping wouldn't be the case but, it's 52 content files anyway you look at it. So, if I name the 52 files based on the week number, then the variable would launch the correct file name during the appropriate week. I'm just trying to find the most efficient, automatic way.


Bookmarks

Posting Permissions

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