Advanced Search

Results 1 to 4 of 4

Thread: Turn content on or off based on the day of the week?

  1. #1
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Turn content on or off based on the day of the week?

    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


    HTML Code:
    <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

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    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.p...he-week-in-PHP

    You just need some if statements and to include an echo statement for the content you want to show that day.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,707
    Thanks
    2
    Thanked 388 Times in 383 Posts

    Default

    Code:
    <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>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  4. #4
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:

    Code:
    $(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

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
  •