August 26, 2015
Sometimes transitional content is used in one area of a website, like to display hours in a Header or Sidebar. Instead of having the client (or yourself!) update this content every day, get your code to update it for you when the weekdays change.
Use inside the_loop to display post data.
Sourced here.
$mon = get_post_meta(get_the_ID(),'monday', true); $tues = get_post_meta(get_the_ID(),'tuesday', true); $wed = get_post_meta(get_the_ID(),'wednesday', true); $thurs = get_post_meta(get_the_ID(),'thursday', true); $fri = get_post_meta(get_the_ID(),'friday', true); $sat = get_post_meta(get_the_ID(),'saturday', true); $sun = get_post_meta(get_the_ID(),'sunday', true); $today = date('N'); if( $today == 1) { ?> <div class="today"> <h3>Today's Hours: <?php echo $mon; ?></h3> </div> <?php } elseif( $today == 2 ) { ?> <div class="today"> <h3>Today's Hours: <?php echo $tues; ?></h3> </div> <?php } elseif( $today == 3 ) { ?> <div class="today"> <h3>Today's Hours: <?php echo $wed; ?></h3> </div> <?php } elseif( $today == 4 ) { ?> <div class="today"> <h3>Today's Hours: <?php echo $thurs; ?></h3> </div> <?php } elseif( $today == 5 ) { ?> <div class="today"> <h3>Today's Hours: <?php echo $fri; ?></h3> </div> <?php } elseif( $today == 6 ) { ?> <div class="today"> <h3>Today's Hours: <?php echo $sat; ?></h3> </div> <?php } elseif( $today == 7 ) { ?> <div class="today"> <h3>Today's Hours: <?php echo $$sun; ?></h3> </div> <?php }