teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードを追記しました

2016/10/16 16:54

投稿

misonya
misonya

スコア25

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