Problem: I would like to alternate the display of two Views depending on whether the current week of the year is odd or even.
Solution:
Use the modulus operator and PHP's date functions to determine whether the current week is odd or even. Then register the shortcode in 3rd-party shortcode arguments and use it in a conditional:
add_shortcode( 'ts-even-odd-week', 'ts_even_odd_week_func'); function ts_even_odd_week_func( $atts, $content ) { $week_number = strftime('%U'); $is_odd = ($week_number % 2 == 1); return $is_odd ? 1 : 0; }
[wpv-conditional if="( '[ts-even-odd-week]' eq '1' )"] This is an odd week - insert the odd View here. [/wpv-conditional] [wpv-conditional if="( '[ts-even-odd-week]' eq '0' )"] This is an even week - insert the even View here. [/wpv-conditional]
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 2 voices.
Last updated by 6 years ago.
Assisted by: Christian Cox.