-
-
Save ounziw/2817734 to your computer and use it in GitHub Desktop.
WordPressの本文の内容を指定日時によって表示するショートコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 指定日時によって内容を表示するショートコード | |
*/ | |
// [datecontent opendate="YmdH" closeDate="YmdH"] | |
function datecontent_func($atts, $content = null) { | |
$nowdate = date_i18n("YmdH"); // 現在の時間を取得 | |
extract(shortcode_atts(array( | |
'opendate' => null, | |
'closedate' => null, | |
), $atts)); | |
if ( ($opendate === null) && ($closedate === null)) { | |
return $content; | |
} elseif ($closedate === null) { | |
if ($nowdate >= $opendate) { | |
return $content; | |
} | |
} elseif ($opendate === null) { | |
if ($nowdate < $closedate) { | |
return $content; | |
} | |
} else { | |
if ( ($nowdate >= $opendate) && ($nowdate < $closedate) ) { | |
return $content; | |
} | |
} | |
} | |
add_shortcode('datecontent', 'datecontent_func'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment