Community Forums › Forums › Archived Forums › General Discussion › Date Detection with Automated Message
- This topic has 6 replies, 3 voices, and was last updated 10 years, 9 months ago by Brad Dalton.
-
AuthorPosts
-
July 12, 2013 at 4:17 pm #50470electricbrickParticipant
Looking for a resource to automatically detect the server date (much like the Genesis right side extras does) but to also output a message based on the day of the week (i.e. open or closed). Anyone know of a simple PHP script or plugin that'll accomplish this?
July 13, 2013 at 4:25 am #50525StewartMemberHi,
This is one simple way you can display message on the day of the week:
add_action( 'genesis_footer', 'sc_date_closed' ); function sc_date_closed() { if( date ( 'w' ) == 5 ) { echo 'closed'; } else { echo 'open'; } }
All you will need to do is change the hook location from genesis_footer to where you want to display, and then just change the day, in the example above I used 5 which is friday.
Sunday - Saturday = 0-6
This is just a simple example but hope it puts you on the right track.
Stewart
WordPress Developer – Need help upgrading to Genesis 2.0? – My Blog
Follow me on TwitterJuly 13, 2013 at 6:59 am #50537Brad DaltonParticipantI forked Stewart's code and used it to create a widget for each day of the week.
For styling it uses Brian Gardners colored content box CSS code so all you need to do is add the CSS code to the end of your child themes style.css file.
July 15, 2013 at 11:44 am #50817electricbrickParticipantHoly smokes, Stewart & Brad -- you guys really came through. Thanks a ton!
I took it a little further and amended the code to work in the header widget area and output the WordPress date:
add_action( 'genesis_header_right', 'week_day_widgets' ); function week_day_widgets() { if ( is_home || is_single() || is_page || is_archive ) if ( date ( 'w' ) == 1 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'mondays-widget' ); echo '</div><!-- end .mondays-widget -->'; } else if( date ( 'w' ) == 2 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'tuesdays-widget' ); echo '</div><!-- end .tuesdays-widget -->'; } else if( date ( 'w' ) == 3 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'wednesdays-widget' ); echo '</div><!-- end .wednesdays-widget -->'; } else if( date ( 'w' ) == 4 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'thursdays-widget' ); echo '</div><!-- end .thursdays-widget -->'; } else if( date ( 'w' ) == 5 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'fridays-widget' ); echo '</div><!-- end .fridays-widget -->'; } else if( date ( 'w' ) == 6 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'saturdays-widget' ); echo '</div><!-- end .saturdays-widget -->'; } else if( date ( 'w' ) == 0 ) { echo '<div class="today"><p>Today is ' . date(get_option('date_format')) . '</p>'; dynamic_sidebar( 'sundays-widget' ); echo '</div><!-- end .sundays-widget -->'; } }
July 15, 2013 at 11:56 am #50824Brad DaltonParticipantTested and works perfectly.
I removed all the conditionals so it displays site wide.
July 15, 2013 at 1:59 pm #50853electricbrickParticipantBrad, you may want to note in your post that the block of code I contributed doesn't contain Brian's content box styling.
July 15, 2013 at 2:16 pm #50854Brad DaltonParticipant -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.