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

質問編集履歴

5

質問内容を修正しました。

2020/09/14 07:54

投稿

idesign0723
idesign0723

スコア18

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,6 @@
1
- Contact Form 7のフォーム内に、お知らせ(カスタム投稿タイプ news)のカテゴリー空き情報(スラッグ aki)の新着2件を出力したいので、自作ショートコードを作ろうと思い、下記のコードをfunctions.phpに書いたのですが、ショトコー{bloglist]がそのまま出されました。
1
+ Contact Form 7のフォーム内に、お知らせ(カスタム投稿タイプ news)のカテゴリー空き情報(スラッグ aki)の新着2件を出力したいので、自作ショートコードを作ろうと思い、下記のコードをfunctions.phpに書いたのですが、get_the_content()の部分が、お客様がビジュアルモードでcontentに入力した改行が抜けて、1行になってしまいます
2
2
 
3
- add_shortcode の代わりにwpcf7_add_shortcode(非推奨)、wpcf7_add_form_tagを入れてみると、エラーます。何か方法はあるでしょうか...
3
+ こちらお客様入力した改行をイキのま出力するにはどうしたら良いでしょうか
4
4
 
5
5
  ```php
6
6
  <?php

4

コードをアドバイスいただいたように修正しました

2020/09/14 07:54

投稿

idesign0723
idesign0723

スコア18

title CHANGED
File without changes
body CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ```php
6
6
  <?php
7
- function get_psttype_list(){
7
+ function get_aki_list(){
8
8
  $args = array(
9
9
  'post_type' => 'news',
10
10
  'taxonomy' => 'news_cat',
@@ -12,18 +12,21 @@
12
12
  'posts_per_page' => 2,
13
13
  'order' => 'DESC'
14
14
  );
15
- $the_news = get_post ( $args );
16
-
17
- $the_query = new WP_Query( $args );
15
+ $top_akinews = new WP_Query( $args );
18
- while ( $the_query->have_posts() ): $the_query->the_post();
19
- $psttype_list='<li><h4 class="akijoho_h4">'.the_title().'</h4><p>'.the_content().'</p></li>';
20
16
 
17
+ if ($top_akinews->have_posts()) :
18
+ $aki_list='<ul>';
19
+ while($top_akinews->have_posts()): $top_akinews->the_post();
20
+ $aki_list.='<li><h4 class="akijoho_h4">'.get_the_title().'</h4><p>'.get_the_content().'</p></li>';
21
+
21
22
  endwhile;
22
-
23
+ $aki_list.='</ul>';
24
+ endif;
25
+ wp_reset_postdata();
23
- return $psttype_list;
26
+ return $aki_list;
24
27
  }
25
-
28
+
26
- add_shortcode('bloglist', 'get_psttype_list');
29
+ wpcf7_add_form_tag('akilist', 'get_aki_list');
27
30
  ?>
28
31
  ```
29
32
  ![実装イメージ](77f1f3e2a4e3364e7aa1e208a58dfa22.png)
@@ -31,12 +34,14 @@
31
34
  Contact Form 7のコンタクトフォーム追加画面に入力したものを掲載しておきます。
32
35
 
33
36
  ```html
37
+ [response]
38
+
34
39
  <table>
35
40
 
36
41
  <tr>
37
42
  <th>お名前(ひらがな)<span class="hissu">必須</span></th>
38
43
  <td>
39
- [text* your-name class:textsp placeholder"はな"]
44
+ [text* your-name class:textsp placeholder"やまだ はな"]
40
45
  </td>
41
46
  </tr>
42
47
 
@@ -57,54 +62,67 @@
57
62
  <tr>
58
63
  <th>来院ご希望日</th>
59
64
  <td>
60
- <h3 id="akijoho_h3">今日・明日の空き情報をチェック!</h3>
65
+ <h3 id="akijoho_h3">今日・明日の空き情報をチェック!</h3>
61
- <div id="akijoho">
66
+ <div id="akijoho">
62
- [bloglist]
67
+ [akilist]
63
- </div>
68
+ </div>
69
+ <div class="kibouWrap">
64
- <ul class="kibou kb01 clearfix">
70
+ <ul class="kibou clearfix">
65
71
  <li class="kbr01">第1希望</li>
66
72
  <li class="kbr02">
67
- [date date01 min:today max:today+6months]
73
+ <span class="hissu">必須</span>
68
74
  </li>
69
- <li class="kbr03 selectbox">
70
- [select jikan01 "ご希望の時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
75
+ </ul>
76
+ <ul class="kibou clearfix">
77
+ <li class="kbr03">
78
+ [text date01 id:select_day1 placeholder"カレンダーから選択"]
71
79
  </li>
72
80
  <li class="kbr04">
73
- <span class="hissu">必須</span>
81
+ [select jikan01 first_as_label "時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
74
82
  </li>
75
83
  </ul>
84
+ </div>
76
85
 
86
+ <div class="kibouWrap">
77
- <ul class="kibou kb02 clearfix">
87
+ <ul class="kibou clearfix">
78
88
  <li class="kbr01">第2希望</li>
79
89
  <li class="kbr02">
80
- [date date02 min:today max:today+6months]
90
+ <span class="ninni">任意</span>
81
91
  </li>
82
- <li class="kbr03 selectbox">
83
- [select jikan02 "ご希望の時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
92
+ </ul>
93
+ <ul class="kibou clearfix">
94
+ <li class="kbr03">
95
+ [text date02 id:select_day2 placeholder"カレンダーから選択"]
84
96
  </li>
85
97
  <li class="kbr04">
86
- <span class="ninni">任意</span>
98
+ [select jikan02 first_as_label "時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
87
99
  </li>
88
100
  </ul>
101
+ </div>
89
102
 
103
+ <div class="kibouWrap">
90
- <ul class="kibou kb03 clearfix">
104
+ <ul class="kibou clearfix">
91
105
  <li class="kbr01">第3希望</li>
92
106
  <li class="kbr02">
93
- [date date03 min:today max:today+6months]
107
+ <span class="ninni">任意</span>
94
108
  </li>
95
- <li class="kbr03 selectbox">
96
- [select jikan03 "ご希望の時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
109
+ </ul>
110
+ <ul class="kibou clearfix">
111
+ <li class="kbr03">
112
+ [text date03 id:select_day3 placeholder"カレンダーから選択"]
97
113
  </li>
98
- <li class="kbr04"><span class="ninni">任意</span></li>
114
+ <li class="kbr04">
115
+ [select jikan03 first_as_label "時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
116
+ </li>
99
117
  </ul>
118
+ </div>
100
119
  </td>
101
120
  </tr>
102
121
 
103
122
  <tr>
104
123
  <th>ご希望日時で予約が確保できない場合の<br>ご希望の曜日と時間帯<span class="ninni">任意</span></th>
105
124
  <td>
106
- [textarea youbi class:content placeholder "(例)ご希望の曜日をご記入ください"]
125
+ [textarea youbi 40x2 class:content placeholder "(例)ご希望の曜日をご記入ください"]<br>
107
- <br><br>
108
126
  [checkbox timezone use_label_element "11〜15時" "15〜18時" "18〜20時"]
109
127
  </td>
110
128
  </tr>
@@ -112,42 +130,37 @@
112
130
  <tr>
113
131
  <th>脱毛のご希望部位<span class="ninni">任意</span></th>
114
132
  <td>
115
- [checkbox kibosejutsu use_label_element "全身脱毛" "VIO脱毛" "顔脱毛" "パーツ別脱毛" "脚脱毛" "針脱毛"]
133
+ [checkbox part use_label_element "全身脱毛" "VIO脱毛" "顔脱毛" "パーツ別脱毛" "脚脱毛" "針脱毛"]
116
134
  </td>
117
135
  </tr>
118
136
 
119
137
  <tr>
120
- <th class="tbh7">脱毛機械のご希望<span class="ninni">任意</span></th>
138
+ <th>脱毛機械のご希望<span class="ninni">任意</span></th>
121
139
  <td>
122
- [radio dayope use_label_element default:1 "なし" "前回と同じ機械" "前回と機械を変更したい"]
140
+ [radio machine use_label_element default:1 "なし" "前回と同じ機械" "前回と機械を変更したい"]<br>
123
- <br><br>
124
- [textarea machinename class:content placeholder "(例)メディオスターNeXT PRO"]
141
+ [textarea machinename 40x3 class:content placeholder "(例)メディオスターNeXT PRO"]
125
142
  </td>
126
143
  </tr>
127
144
 
128
145
  <tr>
129
- <th class="tbh7">麻酔のご希望<span class="ninni">任意</span></th>
146
+ <th>麻酔のご希望<span class="ninni">任意</span></th>
130
147
  <td>
131
- [checkbox masuinashi use_label_element "なし"]
132
- <br><br>
133
- [checkbox creemmasui use_label_element "塗るクリーム麻酔"]
148
+ [checkbox masui use_label_element "なし" "塗るクリーム麻酔" "笑気ガス麻酔"]<br>
134
- <br><br>
135
- [textarea creemmasuiarea class:content placeholder "麻酔を使用したい部位をご記入ください"]
149
+ [textarea creemmasuiarea 40x2 class:content placeholder "塗るクリーム麻酔を使用したい部位をご記入ください"]<br>
136
- <br><br>
137
- [checkbox gassmasui use_label_element "笑気ガス麻酔"]
138
- <br><br>
139
- [textarea gassmasuiarea class:content placeholder "麻酔を使用したい部位をご記入ください"]
150
+ [textarea gassmasuiarea 40x2 class:content placeholder "笑気ガス麻酔を使用したい部位をご記入ください"]
140
151
  </td>
141
152
  </tr>
142
153
 
143
154
  <tr>
144
155
  <th>ご相談がありましたら<br>ご自由にお書きください<span class="ninni">任意</span></th>
145
156
  <td>
146
- [textarea your-message class:content placeholder "(例)脱毛サロンに通ったけれど、また生えてきたのでメールで相談したい。どのプランが良いか、金額や回数も知りたい。"]
157
+ [textarea your-message 40x6 class:content placeholder "(例)脱毛サロンに通ったけれど、また生えてきたのでメールで相談したい。どのプランが良いか、金額や回数も知りたい。"]
147
158
  </td>
148
159
  </tr>
149
160
 
150
161
  </table>
151
162
 
163
+ [response]
164
+
152
- [confirm "確認する"][back "戻る"][submit "送信する"]
165
+ <div id=formbtnWrap>[confirm class:cfm-btn "確認する >"][back class:bk-btn "< 戻る"][submit class:sub-btn "送信する >"]</div>
153
166
  ```

3

コードを追記しました。

2020/09/14 07:50

投稿

idesign0723
idesign0723

スコア18

title CHANGED
File without changes
body CHANGED
@@ -26,4 +26,128 @@
26
26
  add_shortcode('bloglist', 'get_psttype_list');
27
27
  ?>
28
28
  ```
29
- ![実装イメージ](77f1f3e2a4e3364e7aa1e208a58dfa22.png)
29
+ ![実装イメージ](77f1f3e2a4e3364e7aa1e208a58dfa22.png)
30
+
31
+ Contact Form 7のコンタクトフォーム追加画面に入力したものを掲載しておきます。
32
+
33
+ ```html
34
+ <table>
35
+
36
+ <tr>
37
+ <th>お名前(ひらがな)<span class="hissu">必須</span></th>
38
+ <td>
39
+ [text* your-name class:textsp placeholder"はな"]
40
+ </td>
41
+ </tr>
42
+
43
+ <tr>
44
+ <th>電話番号(半角数字)<span class="hissu">必須</span></th>
45
+ <td>
46
+ [tel your-tel class:tel placeholder"09012345678"]<br><span>※ハイフン(ー)なしでご入力ください</span>
47
+ </td>
48
+ </tr>
49
+
50
+ <tr>
51
+ <th>メールアドレス<span class="hissu">必須</span></th>
52
+ <td>
53
+ [email* your-email class:mailsp placeholder"xxxx@xxxx.com"]
54
+ </td>
55
+ </tr>
56
+
57
+ <tr>
58
+ <th>来院ご希望日</th>
59
+ <td>
60
+ <h3 id="akijoho_h3">今日・明日の空き情報をチェック!</h3>
61
+ <div id="akijoho">
62
+ [bloglist]
63
+ </div>
64
+ <ul class="kibou kb01 clearfix">
65
+ <li class="kbr01">第1希望</li>
66
+ <li class="kbr02">
67
+ [date date01 min:today max:today+6months]
68
+ </li>
69
+ <li class="kbr03 selectbox">
70
+ [select jikan01 "ご希望の時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
71
+ </li>
72
+ <li class="kbr04">
73
+ <span class="hissu">必須</span>
74
+ </li>
75
+ </ul>
76
+
77
+ <ul class="kibou kb02 clearfix">
78
+ <li class="kbr01">第2希望</li>
79
+ <li class="kbr02">
80
+ [date date02 min:today max:today+6months]
81
+ </li>
82
+ <li class="kbr03 selectbox">
83
+ [select jikan02 "ご希望の時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
84
+ </li>
85
+ <li class="kbr04">
86
+ <span class="ninni">任意</span>
87
+ </li>
88
+ </ul>
89
+
90
+ <ul class="kibou kb03 clearfix">
91
+ <li class="kbr01">第3希望</li>
92
+ <li class="kbr02">
93
+ [date date03 min:today max:today+6months]
94
+ </li>
95
+ <li class="kbr03 selectbox">
96
+ [select jikan03 "ご希望の時間を選択" "11:00~11:30" "11:30〜12:00" "12:00〜12:30" "12:30〜13:00" "13:00〜13:30" "13:30〜14:00" "14:00〜14:30" "14:30〜15:00" "15:00〜15:30" "15:30〜16:00" "16:00〜16:30" "16:30〜17:00" "17:00〜17:30" "17:30〜18:00" "18:00〜18:30" "18:30〜19:00" "19:00〜19:30" "19:30〜20:00"]
97
+ </li>
98
+ <li class="kbr04"><span class="ninni">任意</span></li>
99
+ </ul>
100
+ </td>
101
+ </tr>
102
+
103
+ <tr>
104
+ <th>ご希望日時で予約が確保できない場合の<br>ご希望の曜日と時間帯<span class="ninni">任意</span></th>
105
+ <td>
106
+ [textarea youbi class:content placeholder "(例)ご希望の曜日をご記入ください"]
107
+ <br><br>
108
+ [checkbox timezone use_label_element "11〜15時" "15〜18時" "18〜20時"]
109
+ </td>
110
+ </tr>
111
+
112
+ <tr>
113
+ <th>脱毛のご希望部位<span class="ninni">任意</span></th>
114
+ <td>
115
+ [checkbox kibosejutsu use_label_element "全身脱毛" "VIO脱毛" "顔脱毛" "パーツ別脱毛" "脚脱毛" "針脱毛"]
116
+ </td>
117
+ </tr>
118
+
119
+ <tr>
120
+ <th class="tbh7">脱毛機械のご希望<span class="ninni">任意</span></th>
121
+ <td>
122
+ [radio dayope use_label_element default:1 "なし" "前回と同じ機械" "前回と機械を変更したい"]
123
+ <br><br>
124
+ [textarea machinename class:content placeholder "(例)メディオスターNeXT PRO"]
125
+ </td>
126
+ </tr>
127
+
128
+ <tr>
129
+ <th class="tbh7">麻酔のご希望<span class="ninni">任意</span></th>
130
+ <td>
131
+ [checkbox masuinashi use_label_element "なし"]
132
+ <br><br>
133
+ [checkbox creemmasui use_label_element "塗るクリーム麻酔"]
134
+ <br><br>
135
+ [textarea creemmasuiarea class:content placeholder "麻酔を使用したい部位をご記入ください"]
136
+ <br><br>
137
+ [checkbox gassmasui use_label_element "笑気ガス麻酔"]
138
+ <br><br>
139
+ [textarea gassmasuiarea class:content placeholder "麻酔を使用したい部位をご記入ください"]
140
+ </td>
141
+ </tr>
142
+
143
+ <tr>
144
+ <th>ご相談がありましたら<br>ご自由にお書きください<span class="ninni">任意</span></th>
145
+ <td>
146
+ [textarea your-message class:content placeholder "(例)脱毛サロンに通ったけれど、また生えてきたのでメールで相談したい。どのプランが良いか、金額や回数も知りたい。"]
147
+ </td>
148
+ </tr>
149
+
150
+ </table>
151
+
152
+ [confirm "確認する"][back "戻る"][submit "送信する"]
153
+ ```

2

画像がアップロードされていなかったので、再度アップロードしました。

2020/09/08 14:32

投稿

idesign0723
idesign0723

スコア18

title CHANGED
File without changes
body CHANGED
@@ -2,27 +2,6 @@
2
2
 
3
3
  add_shortcode の代わりに、wpcf7_add_shortcode(非推奨)、wpcf7_add_form_tagを入れてみると、エラーがでます。何か方法はあるでしょうか...
4
4
 
5
- function get_psttype_list(){
6
- $args = array(
7
- 'post_type' => 'news',
8
- 'taxonomy' => 'news_cat',
9
- 'term' => 'aki',
10
- 'posts_per_page' => 2,
11
- 'order' => 'DESC'
12
- );
13
- $the_news = get_post ( $args );
14
-
15
- $the_query = new WP_Query( $args );
16
- while ( $the_query->have_posts() ): $the_query->the_post();
17
- $psttype_list='<li><h4 class="akijoho_h4">'.the_title().'</h4><p>'.the_content().'</p></li>';
18
-
19
- endwhile;
20
-
21
- return $psttype_list;
22
- }
23
-
24
- add_shortcode('bloglist', 'get_psttype_list');
25
-
26
5
  ```php
27
6
  <?php
28
7
  function get_psttype_list(){
@@ -46,4 +25,5 @@
46
25
 
47
26
  add_shortcode('bloglist', 'get_psttype_list');
48
27
  ?>
49
- ```
28
+ ```
29
+ ![実装イメージ](77f1f3e2a4e3364e7aa1e208a58dfa22.png)

1

コードの表示方法を変更して、実装したい画像を掲載しました

2020/09/08 14:27

投稿

idesign0723
idesign0723

スコア18

title CHANGED
File without changes
body CHANGED
@@ -21,4 +21,29 @@
21
21
  return $psttype_list;
22
22
  }
23
23
 
24
- add_shortcode('bloglist', 'get_psttype_list');
24
+ add_shortcode('bloglist', 'get_psttype_list');
25
+
26
+ ```php
27
+ <?php
28
+ function get_psttype_list(){
29
+ $args = array(
30
+ 'post_type' => 'news',
31
+ 'taxonomy' => 'news_cat',
32
+ 'term' => 'aki',
33
+ 'posts_per_page' => 2,
34
+ 'order' => 'DESC'
35
+ );
36
+ $the_news = get_post ( $args );
37
+
38
+ $the_query = new WP_Query( $args );
39
+ while ( $the_query->have_posts() ): $the_query->the_post();
40
+ $psttype_list='<li><h4 class="akijoho_h4">'.the_title().'</h4><p>'.the_content().'</p></li>';
41
+
42
+ endwhile;
43
+
44
+ return $psttype_list;
45
+ }
46
+
47
+ add_shortcode('bloglist', 'get_psttype_list');
48
+ ?>
49
+ ```