Forums

IF certain day (Sunday, Monday, etc) show certain DIV (2 posts)

  1. ccmovies
    Member
    Posted 1 year ago #

    Hey, I am making a wordpress theme which requires a section to show a certain div depending on the day. For example, if it is Sunday, it will show the "sunday div," if it is Monday, it will show the "monday div," etc.

    How can I accomplish this? It seems like a simple PHP If statement. I am new to both wordpress theme design and PHP, so please explain it out.

    Thank you very much, it is much appreciated!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    suppose that you have some logic/programming background.

    resources:
    http://php.net/manual/en/function.date.php

    'N' ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday)

    http://www.w3schools.com/PHP/php_switch.asp

    <?php switch(date('N')) {
    case 1: ?>
    <div class="monday"> mo<!--whatever--> </div>
    <?php break;
    case 2: ?>
    <div class="tueday"> tu<!--whatever--> </div>
    <?php break;
    case 3: ?>
    <div class="wednesday"> we<!--whatever--> </div>
    <?php break;
    case 4: ?>
    <div class="thursday"> th<!--whatever--> </div>
    <?php break;
    case 5: ?>
    <div class="friday"> fr<!--whatever--> </div>
    <?php break;
    case 6: ?>
    <div class="saturday"> sa<!--whatever--> </div>
    <?php break;
    case 7: ?>
    <div class="sunday"> su<!--whatever--> </div>
    <?php break;
    default:
    } ?>

    you can do the same with 'if/elseif':

    <?php $today = date('N');
    if( $today == 1) { ?>
    <div class="monday"> mo<!--whatever--> </div>
    <?php } elseif( $today == 2 ) { ?>
    <div class="tueday"> tu<!--whatever--> </div>
    <?php } elseif( $today == 3 ) { ?>
    <div class="wednesday"> we<!--whatever--> </div>
    <?php } elseif( $today == 4 ) { ?>
    <div class="thursday"> th<!--whatever--> </div>
    <?php } elseif( $today == 5 ) { ?>
    <div class="friday"> fr<!--whatever--> </div>
    <?php } elseif( $today == 6 ) { ?>
    <div class="saturday"> sa<!--whatever--> </div>
    <?php } elseif( $today == 7 ) { ?>
    <div class="sunday"> su<!--whatever--> </div>
    <?php <?php } ?>

    hope, i got all the brackets right ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic