Error: Could not fetch http://thedevnet.com/wp-content/plugins/gd-star-rating/css/gdsr.css.php?t=0&s=a10i10m20k20c05r05%23121620243046%23121620243240%23s1pchristmas%23s1pcrystal%23s1pdarkness%23s1poxygen%23s1goxygen_gif%23s1pplain%23s1ppumpkin%23s1psoft%23s1pstarrating%23s1pstarscape%23t1pclassical%23t1pstarrating%23t1gstarrating_gif&ver=1.7.2 for caching. You might need to exclude this file in WP Minify options. The Developer Network – Display an image or URL on a specific date

Display an image or URL on a specific date

When running your website, sometimes you only want people to see certain images or urls on certain days. This is most likely to happen when you are running an E-commerce website. Let’s say you have certain images or urls you want seen on specific days, this is one way you can do such a task:

Sample text file (dateText.txt):

  1. default /logo/logo.gif
  2. 2007-04-01 /images/logo1.gif
  3. 2007-06-05 /images/logo2.gif
  4. 2007-08-10 /images/logo3.gif
  5. 2007-09-30 /images/logo4.gif
  6. 2007-12-25 /images/logo5.gif

The function to display the url or image on a specific date:

  1. <?php
  2.     function imagedate(){
  3.          //http://thedevnet.com/php/snippets/display-an-image-or-url-on-a-specific-date/
  4.  //get date by opening file
  5.         $filename = "dateText.txt";
  6.         $handle = fopen($filename, "r");
  7.         $contents = fread($handle, filesize($filename));
  8.         fclose($handle);
  9.         $array = explode("n",$contents);
  10.         foreach($array as $item){
  11.             $arr = explode(" ",$item);
  12.             if(date("Y-m-d") == $arr[0]){
  13.                 $val = $arr[1];
  14.                 $rtur = TRUE;
  15.                 break;
  16.             }else{
  17.                 $rtur = FALSE;
  18.             }
  19.         }
  20.         if($rtur){
  21.             return $val;
  22.         }else{
  23.             $def = explode(" ",$array[0]);
  24.             return $def[1];
  25.         }
  26.     }
  27. ?>

Sample call:

  1. <?php
  2.     include("imagedate.php");
  3.     $url = imagedate();
  4.     echo '<a href="'.$url.'">'.$url.'</a>';
  5. ?>
GD Star Rating
loading...

Originally posted 2009-10-27 19:44:01.

Popularity: 2%

Posted by natster   @   13 July 2010
Tags : , , , , ,

Related Posts

Like this post? Share it!

RSS Digg Twitter StumbleUpon Delicious Technorati Facebook

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

You must be logged in to post a comment.

Previous Post
« 2D Plotter
Next Post
Zoom Crop Image »
Powered by Wordpress   |   Lunated designed by ZenVerse