1.

Solve : Code to make image/text disappear after set period of time?

Answer»

I am the webmaster for the amateur radio club I am a member of. I recently completed a ground-up upgrade to our club's website. One of the new features on the site is a page where equipment for sale/trade/wanted may be listed. As part of the disclaimer, I put that items listed will be removed after 30 days. I remember seeing somewhere online where you can set a time-limit to remove a section of text and images after a set period of time, but I cannot remember where I saw it. An example of what I am talking about is when you go to a website and you see a "NEW" image after a listing. Usually those images are removed after a certain period of time, say 2 to 4 weeks.

I can't remember if what I saw was html coding or JAVASCRIPT coding, but one feature I do remember from it was a "hidden" command which goes into effect after the time has expired. If anyone has advice or can point me to a site where I can figure this out, I appreciate it.

ALSO, I did a search for this question in the forums here and couldn't find anything. However, I may have overlooked it. If I did, I apologize.Are you using a content management system, or is every single page statically coded?Statically coded. This site doesn't need a CMS. This coding need is only needed on one page.Two further questions: can you provide a link to an example page?  And is the web server in question PHP-enabled?The website is www.ncarc.org. The page I am working on is the Swap Shop. And yes, PHP is enabled.Your website doesn't FIT on my 1024 pixels wide screen!

Definitely use PHP, get it to check time and display the content if it's not yet past a certain date, that way the server sends the finished page as it should appear with no need for the client to do any processing on it, and the server won't be overloaded by such a small operation so there's no need to worry about it buckling under the pressure of the PHP script. Quote from: kl0if on January 04, 2012, 08:53:24 AM

The website is www.ncarc.org. The page I am working on is the Swap Shop. And yes, PHP is enabled.

So, there are a few different ways to approach this.  WITHOUT creating a full-blown CMS, I'd be inclined to do something along the following lines:

  • Create a subdir '/swapshop'
  • Place in this subdir text files or HTML snippets containing the details of each advert
  • Save the files with the date included as part of the filename - e.g. 2012-01-04-ad1.txt
  • Use a PHP DirectoryIterator to pull in all the text files, but only display those whose names indicate they are newer than (CURRENT date - 30 days).

How does that sound?  It would be up to you to ensure that the file names followed your chosen convention, since there's not a lot of automation built into this.That would work. However, one thing I engineered into the website redesign is simplicity. In the unlikely event that I need to surrender my duties as webmaster for some reason, I wrote all my code so that anyone with minimal HTML experience can come in behind me and continue to maintain the website. So having a simple method to remove a post after a set period of time would be better. Quote from: kl0if on January 04, 2012, 11:29:29 AM
That would work. However, one thing I engineered into the website redesign is simplicity. In the unlikely event that I need to surrender my duties as webmaster for some reason, I wrote all my code so that anyone with minimal HTML experience can come in behind me and continue to maintain the website. So having a simple method to remove a post after a set period of time would be better.

You can't do this with plain HTML. period. It's going to need a server-side script of some sort.I guess it would be possible to do something similar client-side with javascript - put each item in its own DIV that contains a date stamp somewhere in its ID attribute and then only display those DIVs that are "in date".  But this relies on client-side compliance (javascript being enabled; users not inspecting the code) and would be no simpler than the PHP method.

Essentially, like it or not, what you're talking about is a kind of CMS feature; you are managing content automatically.  Someone with only HTML experience (no javascript, no PHP) is not going to understand this.  Someone with PHP experience will easily understand it however, especially if your code is well documented.  Also, if you provide adequate documentation, any successor web master should be able to follow the basic pattern of creating text files complying to your file naming convention.


Discussion

No Comment Found