Log in

View Full Version : Turn content on or off based on the day of the week?



alexscriptsearch
08-23-2012, 05:41 AM
Hi,

I am using the jQuery cycle plugin to run a basic slider containing 3 slides (A, B, C) of a text header and an image.

I want to be able to display slide A and B on Mon, Wed, Fri, Sun;

then slide A and C on Tue, Thurs, Sat.

So I am looking for some kind of script or PHP based solution to turn content on and off based on the day of the week. Does anyone have any suggestions for the best approach?

Here is a link and an example of my code:

http://www.alexcreedy.com/slide/sample-code-for-forum.html (http://www.alexcreedy.com/slide/sample-code-for-forum.html)


<html>

<head>
<script type="text/javascript" src="/slide/js/jquery-1.5.1.min.js"></script>

<script type="text/javascript" src="/slide/js/jquery.cycle.all.min.js"></script>



<script type="text/javascript">

$(function() {
$('#solutionFade').cycle({

fx: 'fade',
speed: 500,
timeout: 3000,


});
});;


</script>
</head>

<body>


<div id="solutionFade">

<div>
<h2 class="solutionHead">SLIDE A</h2>
<img src="/slide/img/slide_A.jpg"/>
</div>

<div>
<h2 class="solutionHead">SLIDE B</h2>
<img src="/slide/img/slide_B.jpg"/>
</div>

<div>
<h2 class="solutionHead">SLIDE C</h2>
<img src="/slide/img/slide_C.jpg"/>
</div>

</div><!-- /solutionFade -->

</body>

</html>

regards, Alex

djr33
08-23-2012, 06:22 AM
You can easily find this information on google: "content by day of the week php"

This example is very easy:
http://forum.hostek.com/showthread.php?404-Different-page-content-based-on-day-of-the-week-in-PHP

You just need some if statements and to include an echo statement for the content you want to show that day.

vwphillips
08-23-2012, 08:09 AM
<html>

<head>
<script type="text/javascript" src="http://www.alexcreedy.com/slide/js/jquery-1.5.1.min.js"></script>

<script type="text/javascript" src="http://www.alexcreedy.com/slide/js/jquery.cycle.all.min.js"></script>



</head>

<body>


<div id="solutionFade">

<div>
<h2 class="solutionHead">SLIDE A</h2>
<img src="http://www.alexcreedy.com/slide/img/slide_A.jpg"/>
</div>

<div>
<h2 class="solutionHead">SLIDE B</h2>
<img src="http://www.alexcreedy.com/slide/img/slide_B.jpg"/>
</div>

<div>
<h2 class="solutionHead">SLIDE C</h2>
<img src="http://www.alexcreedy.com/slide/img/slide_C.jpg"/>
</div>

</div><!-- /solutionFade -->

<script type="text/javascript">
//I want to be able to display slide A and B on Mon, Wed, Fri, Sun;
//then slide A and C on Tue, Thurs, Sat.
var day=new Date().getDay();
var div=document.getElementById('solutionFade');
div.removeChild(div.getElementsByTagName('DIV')[day==2||day==4||day==6?1:2]);

$(function() {
$('#solutionFade').cycle({

fx: 'fade',
speed: 500,
timeout: 3000


});
});;


</script>
</body>

</html>

alexscriptsearch
09-04-2012, 12:32 AM
Thanks very much for the answers, i'm able to get it working now.

Someone gave me a similar jquery solution on stack overflow, for your interest, which also works:



$(function() {
var index = ($.inArray((new Date()).getDay(), [0, 1, 3, 5]) > -1) ? 2 : 1;
$("#solutionFade").find('div').eq(index).remove().end().end().cycle({
fx: 'fade',
speed: 500,
timeout: 3000
});
});


cheers,
Alex