質問編集履歴

2

例示用ドメインの修正

2016/12/30 10:30

投稿

umauman
umauman

スコア57

test CHANGED
File without changes
test CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
  その年をクリックするとNot foundになってしまいます。
38
38
 
39
- http://xxx.com/blog/2013/ ←Not found
39
+ http://example.com/blog/2013/ ←Not found
40
40
 
41
41
 
42
42
 

1

記述ミス

2016/12/30 10:30

投稿

umauman
umauman

スコア57

test CHANGED
File without changes
test CHANGED
@@ -174,17 +174,47 @@
174
174
 
175
175
  ```php
176
176
 
177
+
178
+
179
+ add_filter('getarchives_where', 'custom_archives_where', 10, 2);
180
+
181
+ add_filter('getarchives_join', 'custom_archives_join', 10, 2);
182
+
183
+
184
+
185
+ function custom_archives_join($x, $r) {
186
+
187
+
188
+
177
189
  if(!is_home()){ //←これを追加しました
178
190
 
179
191
 
180
192
 
181
- add_filter('getarchives_where', 'custom_archives_where', 10, 2);
182
-
183
- add_filter('getarchives_join', 'custom_archives_join', 10, 2);
184
-
185
-
186
-
187
- function custom_archives_join($x, $r) {
193
+ global $wpdb;
194
+
195
+ $cat_ID = $r['cat'];
196
+
197
+ if (isset($cat_ID)) {
198
+
199
+ return $x . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
200
+
201
+ } else {
202
+
203
+ return $x;
204
+
205
+ }
206
+
207
+
208
+
209
+ } //←これを追加しました
210
+
211
+
212
+
213
+ }
214
+
215
+
216
+
217
+ function custom_archives_where($x, $r) {
188
218
 
189
219
 
190
220
 
@@ -198,11 +228,11 @@
198
228
 
199
229
  if (isset($cat_ID)) {
200
230
 
201
- return $x . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
202
-
203
- } else {
204
-
205
- return $x;
231
+ return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($cat_ID)";
232
+
233
+ } else {
234
+
235
+ $x;
206
236
 
207
237
  }
208
238
 
@@ -216,7 +246,7 @@
216
246
 
217
247
 
218
248
 
219
- function custom_archives_where($x, $r) {
249
+ function wp_get_cat_archives($opts, $cat) {
220
250
 
221
251
 
222
252
 
@@ -224,17 +254,47 @@
224
254
 
225
255
 
226
256
 
257
+ $args = wp_parse_args($opts, array('echo' => '1')); // default echo is 1.
258
+
259
+ $echo = $args['echo'] != '0'; // remember the original echo flag.
260
+
227
- global $wpdb;
261
+ $args['echo'] = 0;
228
-
262
+
229
- $cat_ID = $r['cat'];
263
+ $args['cat'] = $cat;
264
+
265
+
266
+
230
-
267
+ $tag = ($args['format'] === 'option') ? 'option' : 'li';
268
+
269
+
270
+
271
+ $archives = wp_get_archives(build_query($args));
272
+
273
+ $archs = explode('</'.$tag.'>', $archives);
274
+
275
+ $links = array();
276
+
277
+
278
+
279
+ foreach ($archs as $archive) {
280
+
281
+ $link = preg_replace("/='([^']+)'/", "='$1?cat={$cat}'", $archive);
282
+
283
+ array_push($links, $link);
284
+
285
+ }
286
+
287
+ $result = implode('</'.$tag.'>', $links);
288
+
289
+
290
+
231
- if (isset($cat_ID)) {
291
+ if ($echo) {
232
-
292
+
233
- return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($cat_ID)";
293
+ echo $result;
234
-
294
+
235
- } else {
295
+ } else {
236
-
296
+
237
- $x;
297
+ return $result;
238
298
 
239
299
  }
240
300
 
@@ -246,68 +306,6 @@
246
306
 
247
307
  }
248
308
 
249
-
250
-
251
- function wp_get_cat_archives($opts, $cat) {
252
-
253
-
254
-
255
- if(!is_home()){ //←これを追加しました
256
-
257
-
258
-
259
- $args = wp_parse_args($opts, array('echo' => '1')); // default echo is 1.
260
-
261
- $echo = $args['echo'] != '0'; // remember the original echo flag.
262
-
263
- $args['echo'] = 0;
264
-
265
- $args['cat'] = $cat;
266
-
267
-
268
-
269
- $tag = ($args['format'] === 'option') ? 'option' : 'li';
270
-
271
-
272
-
273
- $archives = wp_get_archives(build_query($args));
274
-
275
- $archs = explode('</'.$tag.'>', $archives);
276
-
277
- $links = array();
278
-
279
-
280
-
281
- foreach ($archs as $archive) {
282
-
283
- $link = preg_replace("/='([^']+)'/", "='$1?cat={$cat}'", $archive);
284
-
285
- array_push($links, $link);
286
-
287
- }
288
-
289
- $result = implode('</'.$tag.'>', $links);
290
-
291
-
292
-
293
- if ($echo) {
294
-
295
- echo $result;
296
-
297
- } else {
298
-
299
- return $result;
300
-
301
- }
302
-
303
-
304
-
305
- } //←これを追加しました
306
-
307
-
308
-
309
- }
310
-
311
309
  ```
312
310
 
313
311