XF 1.3 Syntax to output the day of the month

motowebmaster

Well-known member
I'm working on an idea to change one particular header graphic daily, and would maintain a folder with 31 versions of the image within it. Each one would be something like image01.png, image02.png, & etc.

I saw something in the manual regarding date/time, but does something exist that would show only the day of the month?
 
You could write yourself a simple php to output the image wished and call it as an image. I can't give you a general solution because it differs depending where and in which format the images are..

If you have them all simply put in the same folder and they are in the same format (e.g. jpg), you can create a php file in the same folder with the following content:
PHP:
<?php


// basic headers
header("Content-type: image/png");
header("Expires: Mon, 1 Jan 2099 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

// get the file name
$file= 'Image ('.date ('d',time()).').jpg';
// get the size for content length
$size= filesize($file);
header("Content-Length: $size bytes");
// output the file contents
readfile($file);


?>

You then need to rename the images to "Image (1).jpg" to "Image (31).jpg". You then simply call the php-file within your template as if it would be an image.

If they are in different folders and/or use different names, you'll need a slightly different approach:

PHP:
<?php

$files[1] = 'Relative/Path/To/Image/1.jpg';
$files[2] = 'Relative/Path/To/Image/2.png';
$files[3] = '';
$files[4] = '';
$files[5] = '';
$files[6] = '';
$files[7] = '';
$files[8] = '';
$files[9] = '';
$files[10] = '';
$files[11] = '';
$files[12] = '';
$files[13] = '';
$files[14] = '';
$files[15] = '';
$files[16] = '';
$files[17] = '';
$files[18] = '';
$files[19] = '';
$files[20] = '';
$files[21] = '';
$files[22] = '';
$files[23] = '';
$files[24] = '';
$files[25] = '';
$files[26] = '';
$files[27] = '';
$files[28] = '';
$files[29] = '';
$files[30] = '';
$files[31] = '';

// basic headers
header("Content-type: image/".substr($files[intval(date ('d',time()))], -3));
header("Expires: Mon, 1 Jan 2099 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

// get the file name
$file=$files[intval(date ('d',time()))];
// get the size for content length
$size= filesize($file);
header("Content-Length: $size bytes");
// output the file contents
readfile($file);


?>

Put that file somehwere, where you'll remember and fill the array-fields (between the ' ) with the right relative paths to the images, then use the php-file as normal image in your template again.
 
Last edited:
That's a very "over engineered" solution, albeit one that should work. Here's something a bit more simple.

To get the current day of the month in the template:

Code:
{xen:date $serverTime, 'd'}


So, effectively, all you need is files named accordingly and the usage that will work is something like:

Code:
<img src="image{xen:date $serverTime, 'd'}.png" />

That would, right now, attempt to load an image with a source of image13.png.
 
That's a very "over engineered" solution, albeit one that should work. Here's something a bit more simple.

To get the current day of the month in the template:

Code:
{xen:date $serverTime, 'd'}


So, effectively, all you need is files named accordingly and the usage that will work is something like:

Code:
<img src="image{xen:date $serverTime, 'd'}.png" />

That would, right now, attempt to load an image with a source of image13.png.

As long as they are all the same format, that is definitly a simpler solution than my first one, but if he wants to use different formats/directories, my second solution probably does a better job.
 
That's a very "over engineered" solution, albeit one that should work. Here's something a bit more simple.

To get the current day of the month in the template:

Code:
{xen:date $serverTime, 'd'}


So, effectively, all you need is files named accordingly and the usage that will work is something like:

Code:
<img src="image{xen:date $serverTime, 'd'}.png" />

That would, right now, attempt to load an image with a source of image13.png.

Thanks Chris!
 
Top Bottom