現在の日付けを取得し、A〜B日以内ならCSSを適応。それ以外は処理しないというものを作りたいのですがうまく動きません。
このような処理は複雑なのでしょうか?
PHP
1$target_day1 = '2016/11/01'; 2$target_day2 = '2016/12/31'; 3if (get_the_date() > $target_day1) { 4 echo '<link rel="stylesheet" href="http://localhost/wp-content/themes/test/red.css" type="text/css" media="all" />'; 5 }elseif (get_the_date() < $target_day2) { 6 echo '<link rel="stylesheet" href="http://localhost/wp-content/themes/test/red.css" type="text/css" media="all" />'; 7 }else{ 8 //どちらにも該当しない場合、処理しない 9 }
11月1日以降であればCSSを適応する。
そうじゃなければ、12月31日未満であれば適応しない。
それも違えば何もしないと記述したのですが、よくよく考えれば、day1〜day2の内という指定がないので永年ずっと出てしまう現象です。
参考にしたサイトがこちらです。
http://pluswordpress.com/get_the_date/
回答3件
あなたの回答
tips
プレビュー