Skip to content

Instantly share code, notes, and snippets.

@ounziw
Forked from gatespace/datecontent-shortcode.php
Created May 28, 2012 06:52
Show Gist options
  • Save ounziw/2817734 to your computer and use it in GitHub Desktop.
Save ounziw/2817734 to your computer and use it in GitHub Desktop.
WordPressの本文の内容を指定日時によって表示するショートコード
/**
* 指定日時によって内容を表示するショートコード
*/
// [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