質問編集履歴
1
周辺のソースコードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,8 +58,6 @@
|
|
58
58
|
|
59
59
|
|
60
60
|
|
61
|
-
|
62
|
-
|
63
61
|
##エラーの修正方法が分かりません
|
64
62
|
|
65
63
|
ウィジェットに関するエラーのようですが、この文字列を削除しても問題ないでしょうか。
|
@@ -71,3 +69,239 @@
|
|
71
69
|
調べても解決策が分からず、質問させて頂きました。
|
72
70
|
|
73
71
|
よろしくお願い致します。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
##念の為周辺のコードも記載しておきます
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
5019行目から
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
// 設定フォームを出力するメソッド
|
84
|
+
|
85
|
+
function form( $instance ) {
|
86
|
+
|
87
|
+
?>
|
88
|
+
|
89
|
+
<p>
|
90
|
+
|
91
|
+
<label for="<?php echo $this->get_field_id('body'); ?>">広告タグ:</label>
|
92
|
+
|
93
|
+
<textarea class="widefat" rows="8" id="<?php echo $this->get_field_id('body'); ?>" name="<?php echo $this->get_field_name('body'); ?>"><?php echo @$instance['body']; ?></textarea>
|
94
|
+
|
95
|
+
</p>
|
96
|
+
|
97
|
+
<?php
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
add_action( 'widgets_init', create_function( '', 'return register_widget( "AdWidgetItemClass" );' ) );
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
//////////////////////////////////////////////////
|
116
|
+
|
117
|
+
//人気記事一覧ウィジェットアイテム
|
118
|
+
|
119
|
+
//////////////////////////////////////////////////
|
120
|
+
|
121
|
+
class Popular_Posts extends WP_Widget {
|
122
|
+
|
123
|
+
function __construct() {
|
124
|
+
|
125
|
+
$widget_option = array('description' => 'PV数の多い順で記事を表示');
|
126
|
+
|
127
|
+
parent::__construct( false, $name = '[LION]人気記事', $widget_option );
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
// 設定フォームを出力するメソッド
|
134
|
+
|
135
|
+
function form($instance) {
|
136
|
+
|
137
|
+
$time = !empty($instance['time']) ? 'checked' : '';
|
138
|
+
|
139
|
+
?>
|
140
|
+
|
141
|
+
<p>
|
142
|
+
|
143
|
+
<p>
|
144
|
+
|
145
|
+
<label for="<?php echo $this->get_field_id('title'); ?>">タイトル:</label>
|
146
|
+
|
147
|
+
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( @$instance['title'] ); ?>">
|
148
|
+
|
149
|
+
</p>
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
<p>
|
154
|
+
|
155
|
+
<label for="<?php echo $this->get_field_id('number'); ?>">表示する投稿数:</label>
|
156
|
+
|
157
|
+
<input class="tiny-text" type="number" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" value="<?php echo esc_attr( @$instance['number'] ); ?>" step="1" min="1" max="10" size="3">
|
158
|
+
|
159
|
+
</p>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<p>
|
164
|
+
|
165
|
+
<input class="checkbox" type="checkbox" <?php echo $time; ?> id="<?php echo $this->get_field_id('time'); ?>" name="<?php echo $this->get_field_name('time'); ?>" />
|
166
|
+
|
167
|
+
<label for="<?php echo $this->get_field_id('time'); ?>">投稿日を表示しますか ?</label>
|
168
|
+
|
169
|
+
</p>
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
</p>
|
174
|
+
|
175
|
+
<?php
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
//カスタマイズ欄の入力内容が変更された場合の処理
|
182
|
+
|
183
|
+
function update($new_instance, $old_instance) {
|
184
|
+
|
185
|
+
$instance = $old_instance;
|
186
|
+
|
187
|
+
$instance['title'] = strip_tags($new_instance['title']);
|
188
|
+
|
189
|
+
$instance['number'] = is_numeric($new_instance['number']) ? $new_instance['number'] : 5;
|
190
|
+
|
191
|
+
$instance['time'] = strip_tags($new_instance['time']);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
return $instance;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
// 設定を表示するメソッド
|
204
|
+
|
205
|
+
function widget($args, $instance) {
|
206
|
+
|
207
|
+
extract($args);
|
208
|
+
|
209
|
+
echo $before_widget;
|
210
|
+
|
211
|
+
$title = NULL;
|
212
|
+
|
213
|
+
if(!empty($instance['title'])) {
|
214
|
+
|
215
|
+
$title = apply_filters('widget_title', $instance['title'] );
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
if ($title) {
|
222
|
+
|
223
|
+
echo $before_title . $title . $after_title;
|
224
|
+
|
225
|
+
} else {
|
226
|
+
|
227
|
+
echo '<h2 class="heading heading-widget">RANKING</h2>';
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
$number = !empty($instance['number']) ? $instance['number'] : 5;
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
get_the_ID();
|
238
|
+
|
239
|
+
$args = array(
|
240
|
+
|
241
|
+
'meta_key'=> 'post_views_count',
|
242
|
+
|
243
|
+
'orderby' => 'meta_value_num',
|
244
|
+
|
245
|
+
'order' => 'DESC',
|
246
|
+
|
247
|
+
'ignore_sticky_posts' => '1',
|
248
|
+
|
249
|
+
'posts_per_page' => $number
|
250
|
+
|
251
|
+
);
|
252
|
+
|
253
|
+
$my_query = new WP_Query( $args );?>
|
254
|
+
|
255
|
+
<ol class="rankListWidget">
|
256
|
+
|
257
|
+
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
|
258
|
+
|
259
|
+
<li class="rankListWidget__item<?php if ( get_option('fit_post_eyecatch') == 'value2' ) : ?> rankListWidget__item-noeye<?php endif; ?>">
|
260
|
+
|
261
|
+
<?php if ( get_option('fit_post_eyecatch') != 'value2' ) : ?>
|
262
|
+
|
263
|
+
<div class="eyecatch eyecatch-widget u-txtShdw">
|
264
|
+
|
265
|
+
<a href="<?php the_permalink(); ?>">
|
266
|
+
|
267
|
+
<?php if(has_post_thumbnail()) {the_post_thumbnail('icatch');} else {echo '<img src="'.get_template_directory_uri().'/img/img_no.gif" alt="NO IMAGE"/>';}?>
|
268
|
+
|
269
|
+
</a>
|
270
|
+
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<?php endif; ?>
|
274
|
+
|
275
|
+
<h3 class="rankListWidget__title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
|
276
|
+
|
277
|
+
<div class="dateList dateList-widget<?php if ( get_option('fit_post_eyecatch') == 'value2' ) : ?> dateList-noeye<?php endif; ?>">
|
278
|
+
|
279
|
+
<?php if(!empty($instance['time'])) : ?><span class="dateList__item icon-calendar"><?php the_time('Y.m.d'); ?></span><?php endif; ?>
|
280
|
+
|
281
|
+
<span class="dateList__item icon-folder"><?php the_category(' ');?></span>
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
285
|
+
</li>
|
286
|
+
|
287
|
+
<?php endwhile; wp_reset_postdata(); ?>
|
288
|
+
|
289
|
+
</ol>
|
290
|
+
|
291
|
+
<?php
|
292
|
+
|
293
|
+
echo $after_widget;
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
add_action( 'widgets_init', create_function( '', 'return register_widget( "Popular_Posts" );' ) );
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
```
|