質問編集履歴

1

記載しているファイル名などを追記

2021/06/21 14:00

投稿

ringoringogogo
ringoringogogo

スコア15

test CHANGED
File without changes
test CHANGED
@@ -65,3 +65,165 @@
65
65
 
66
66
 
67
67
  大変恐れ入りますが、以上よろしくお願いいたします。
68
+
69
+
70
+
71
+ 以下、追記いたします。
72
+
73
+
74
+
75
+
76
+
77
+ 以下のようにWP_Widgetを継承したクラスのform ファンクションに記載しています。
78
+
79
+ やりたいこととしては、指定した数だけテキストフィールドを増やしたいと思っています。
80
+
81
+ (ギャラリーウィジェットのようなものが理想なのですがframeの使い方がわからないのでこの方法で試しています・・・。)
82
+
83
+
84
+
85
+ 以下、function.phpに記載しているコードです。
86
+
87
+
88
+
89
+
90
+
91
+ <?php
92
+
93
+
94
+
95
+ class Images_Slider extends WP_Widget
96
+
97
+ {
98
+
99
+ function Images_Slider()
100
+
101
+ {
102
+
103
+ $widget_option = array('description' => '複数の画像とリンクを設定');
104
+
105
+ parent::__construct(false, $name = '画像スライダー', $widget_option);
106
+
107
+ }
108
+
109
+
110
+
111
+ function form($instance)
112
+
113
+ {
114
+
115
+ ?>
116
+
117
+ <div class="okikae">
118
+
119
+ <p>もとの内容です
120
+
121
+ </p>
122
+
123
+ </div>
124
+
125
+
126
+
127
+ <form method="post" action="confirm">
128
+
129
+ <div class="form-setting-number" id="form-setting-number">
130
+
131
+ <p>設定する画像の数</p>
132
+
133
+ <select id="form-setting-number">
134
+
135
+ <option value="1">1</option>
136
+
137
+ <option value="2">2</option>
138
+
139
+ <option value="3">3</option>
140
+
141
+ </select>
142
+
143
+ </div>
144
+
145
+ </form>
146
+
147
+
148
+
149
+
150
+
151
+ <form method="post" action="confirm">
152
+
153
+ <div class="form-block" id="form_block[0]">
154
+
155
+ <!-- Closeボタン -->
156
+
157
+ <span class="close" title="Close" style="display: none;">-</span>
158
+
159
+
160
+
161
+ <p>Name:<input type="text" name="name[0]" id="name[0]" /></p>
162
+
163
+ <p>
164
+
165
+ <label for="<?php echo $this->get_field_id('imageurl'); ?>">画像URL:</label>
166
+
167
+ <input type="url" name="imageurl" class="widefat" id="<?php echo $this->get_field_id('imageurl'); ?>" name="<?php echo $this->get_field_name('imageurl'); ?>" value="<?php echo esc_attr(@$instance['imageurl']); ?>">
168
+
169
+ </p>
170
+
171
+ <p><label for="<?php echo $this->get_field_id('targeturl'); ?>">リンク先:</label>
172
+
173
+ <input type="url" name="targeturl" class="widefat" id="<?php echo $this->get_field_id('targeturl'); ?>" name="<?php echo $this->get_field_name('targeturl'); ?>" value="<?php echo esc_attr(@$instance['targeturl']); ?>">
174
+
175
+ </p>
176
+
177
+ </div>
178
+
179
+
180
+
181
+ </form>
182
+
183
+
184
+
185
+ <script>
186
+
187
+ //セレクトボックスが切り替わったら発動
188
+
189
+ jQuery(function() {
190
+
191
+
192
+
193
+ jQuery('select').change(function() {
194
+
195
+ console.log("値変更されました");
196
+
197
+ //選択したvalue値を変数に格納
198
+
199
+ var settingnumber = jQuery(this).val();
200
+
201
+ var okikaetext = "";
202
+
203
+ for (var i=0; i<settingnumber; i++) {
204
+
205
+ var idname="imageurl"+(i+1);
206
+
207
+ console.log("id name:"+idname);
208
+
209
+ okikaetext = okikaetext +   ' <p><label for="<?php echo $this->get_field_id(idname); ?>">画像URL:</label><input type="url" name="imageurl" class="widefat" id="<?php echo $this->get_field_id('imageurl'); ?>" name="<?php echo $this->get_field_name('imageurl'); ?>" value="<?php echo esc_attr(@$instance['imageurl']); ?>"></p>'
210
+
211
+ }
212
+
213
+
214
+
215
+ jQuery('.okikae').html(okikaetext);
216
+
217
+
218
+
219
+ });
220
+
221
+ });
222
+
223
+
224
+
225
+ </script>
226
+
227
+
228
+
229
+ 大変恐れ入りますが、お気づきの点ございましたらなんでもご指摘いただけると幸いです・・・。