質問編集履歴

4

誤字修正

2016/11/20 11:17

投稿

happyturn
happyturn

スコア12

test CHANGED
File without changes
test CHANGED
@@ -116,7 +116,7 @@
116
116
 
117
117
  echo paginate_links( array(
118
118
 
119
- 'base' => 'http://aftereffects-pc.sakura.ne.jp/seijika_com/?s=' . $key . '%_%',
119
+ 'base' => 'http://hogehoge/?s=' . $key . '%_%',
120
120
 
121
121
  'format' => '&page=%#%',
122
122
 

3

コードを修正致しました。

2016/11/20 11:17

投稿

happyturn
happyturn

スコア12

test CHANGED
File without changes
test CHANGED
@@ -180,8 +180,6 @@
180
180
 
181
181
  if( is_admin() || ! $query->is_main_query() ){
182
182
 
183
- $query->set( 'posts_per_page', '4' );
184
-
185
183
  return;
186
184
 
187
185
  }

2

回答を受けて加筆致しました。

2016/11/20 11:12

投稿

happyturn
happyturn

スコア12

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,9 @@
40
40
 
41
41
  ###該当のソースコード
42
42
 
43
+ ▼▼ご回答を頂いて自分なりに修正しました。 どこかがまだ間違っているようです。 いろいろと試しましたがもうさっぱり見当もつきません。 全文を掲載しておきます。▼▼
44
+
43
- ▼以下search.php全文
45
+ search.php全文修正後
44
46
 
45
47
  ```
46
48
 
@@ -58,322 +60,282 @@
58
60
 
59
61
  <div class="cf">
60
62
 
61
- <?php $searchResults = new WP_Query("s=$s & showposts=-1");
62
-
63
- $key = wp_specialchars($s, 1); ?>
64
-
65
63
  <h3><?php echo $key ?>の検索結果一覧</h3>
66
64
 
65
+ <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
66
+
67
+ <article>
68
+
69
+ <div class="list-block cf">
70
+
71
+ <div class="left-box thumbnail-box">
72
+
73
+ <a class="thumbnail-a" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(150,)); ?></a>
74
+
75
+ </div>
76
+
77
+ <div class="right-box">
78
+
79
+ <dl>
80
+
81
+ <dt>所属</dt>
82
+
83
+ <dd class="party-name"><?php the_category(); ?></dd>
84
+
85
+ <dd><?php the_tags('','',''); ?></dd>
86
+
87
+ <dd class="region"><?php echo post_custom('region1'); echo post_custom('region2'); ?></dd>
88
+
89
+ </dl>
90
+
91
+ <p class="name"><a href="<?php the_permalink(); ?>"><?php echo post_custom('name'); ?></a></p>
92
+
93
+ <div class="link-box">
94
+
95
+ <?php $cat_slug = get_the_category(); $cat_slug = $cat_slug[0]; ?>
96
+
97
+ <p><a href="<?php echo get_home_url(),"/",$cat_slug->category_nicename ?>">>地域詳細を見る</a></p>
98
+
99
+ <p><a href="<?php the_permalink(); ?>">>プロフィールを見る</a></p>
100
+
101
+ </div>
102
+
103
+ </div>
104
+
105
+ </div>
106
+
107
+ </article>
108
+
109
+ <?php endwhile; ?>
110
+
111
+ <div class="s-page-nav cf">
112
+
67
113
  <?php
68
114
 
69
- global $wp_query;
115
+ $big = 999999999;
116
+
70
-
117
+ echo paginate_links( array(
118
+
119
+ 'base' => 'http://aftereffects-pc.sakura.ne.jp/seijika_com/?s=' . $key . '%_%',
120
+
121
+ 'format' => '&page=%#%',
122
+
71
- $paged = get_query_var('paged') ? get_query_var('paged') : 1 ;
123
+ 'current' => max( 0, get_query_var('page') ),
72
-
73
- $args = array(
124
+
74
-
75
- 'paged' => $paged,
125
+ 'total' => $the_query->max_num_pages,
76
-
126
+
77
- 'post_type' => array(
127
+ 'end_size' => 5,
78
-
128
+
79
- 'post',
129
+ 'type' => 'list',
130
+
80
-
131
+ 'show_all' => 'false'
132
+
81
- ));
133
+ ) );
82
-
83
-
84
-
85
- $args['meta_query'] = array(
134
+
86
-
87
- array( 'key' => 'region0', 'value' => $key, 'compare' => '=', 'type' => 'CHAR'),
88
-
89
- array( 'key' => 'region1', 'value' => $key, 'compare' => '=', 'type' => 'CHAR'),
90
-
91
- array( 'key' => 'region2', 'value' => $key, 'compare' => '=', 'type' => 'CHAR'),
92
-
93
- 'relation'=>'or'
94
-
95
- );
96
-
97
- ?>
98
-
99
- <?php
100
-
101
- $region1 = post_custom('region1');
102
-
103
- $region2 = post_custom('region2');
104
-
105
- $cat_id=$post_cat[0]->cat_ID;
106
-
107
- $cat_name=$post_cat[0]->cat_name;
108
-
109
- $cat = get_the_category();
135
+ wp_reset_postdata();
110
-
111
- $cat = $cat[0];
112
136
 
113
137
  ?>
114
138
 
115
- <?php
116
-
117
- $the_query = new WP_Query($args);
118
-
119
- ?>
120
-
121
-
122
-
123
- <?php if($the_query -> have_posts()): ?>
124
-
125
- <?php while($the_query -> have_posts()): $the_query -> the_post(); ?>
126
-
127
- <article>
128
-
129
- <div class="list-block cf">
130
-
131
- <div class="left-box thumbnail-box">
132
-
133
- <a class="thumbnail-a" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(150,)); ?></a>
139
+ </div>
140
+
141
+ <?php else : ?>
142
+
143
+ <p class="notfound">該当者がいません。</p>
144
+
145
+ <?php endif; ?>
146
+
147
+ </div>
148
+
149
+
150
+
151
+ </div>
152
+
153
+ </section>
154
+
155
+ </div>
156
+
157
+ <?php get_sidebar(); ?>
158
+
159
+ </div>
160
+
161
+ </div>
162
+
163
+ <?php get_footer(); ?>
164
+
165
+ ```
166
+
167
+
168
+
169
+
170
+
171
+ function.phpの全文修正後
172
+
173
+ ```
174
+
175
+ <?php
176
+
177
+ function change_posts_per_page($query) {
178
+
179
+ /* 管理画面,メインクエリに干渉しないために必須 */
180
+
181
+ if( is_admin() || ! $query->is_main_query() ){
182
+
183
+ $query->set( 'posts_per_page', '4' );
184
+
185
+ return;
186
+
187
+ }
188
+
189
+ if ( $query->is_search() ) {
190
+
191
+ $query->set( 'post_type','post' );
192
+
193
+ $query->set( 'paged',get_query_var( 'paged' ) );
194
+
195
+ $key = $query->get('s');
196
+
197
+ $taxquery = array(
198
+
199
+ array( 'key' => 'region0', 'value' => $key, 'compare' => '=', 'type' => 'CHAR'),
200
+
201
+ array( 'key' => 'region1', 'value' => $key, 'compare' => '=', 'type' => 'CHAR'),
202
+
203
+ array( 'key' => 'region2', 'value' => $key, 'compare' => '=', 'type' => 'CHAR'),
204
+
205
+ 'relation'=>'or'
206
+
207
+ );
208
+
209
+ $query->set( 'tax_query' , $taxquery );
210
+
211
+ return;
212
+
213
+ }
214
+
215
+ }
216
+
217
+ add_action( 'pre_get_posts', 'change_posts_per_page' );
218
+
219
+ // アイキャッチ画像を有効にする。
220
+
221
+ add_theme_support('post-thumbnails');
222
+
223
+ if (function_exists('add_theme_support')) {
224
+
225
+ add_theme_support('post-thumbnails');
226
+
227
+ add_image_size( 'pc_single_thumbnails', 800, 500, true );
228
+
229
+ add_image_size( 'pc_list_thumbnails', 608, 380, true );
230
+
231
+ add_image_size( 'main_thumbnails', 480, 300, true );
232
+
233
+ add_image_size( 'mobile_list_thumbnails', 240, 180, true );
234
+
235
+ }
236
+
237
+ //ここからポピュラーポストのカスタマイズ設定
238
+
239
+ function my_custom_single_popular_post( $post_html, $p, $instance ){
240
+
241
+ $thumbnail_id = get_post_thumbnail_id( $p->id);
242
+
243
+ $thumbnail_img = wp_get_attachment_image_src( $thumbnail_id, 'main_thumbnails' );
244
+
245
+ $post_cat=get_the_category( $p->id);
246
+
247
+ $cat_id=$post_cat[0]->cat_ID;
248
+
249
+ $cat_name=$post_cat[0]->cat_name;
250
+
251
+ $cat = get_the_category();
252
+
253
+ $cat = $cat[0];
254
+
255
+ $cat_slug = $post_cat[0]->category_nicename;
256
+
257
+ $post_tag=get_the_tags( $p->id);
258
+
259
+ $tag_id=$post_tag[0]->name;
260
+
261
+ $custom_name = get_post_meta($p->id, 'name', true);
262
+
263
+ $custom_region1 = get_post_meta($p->id, 'region1', true);
264
+
265
+ $custom_region2 = get_post_meta($p->id, 'region2', true);
266
+
267
+ $custom_id= $p->id;
268
+
269
+ //$excerpt = get_post_field( post_content, $p->id, display );
270
+
271
+ $output = '
272
+
273
+ <article>
274
+
275
+ <div class="list-block cf">
276
+
277
+ <div class="left-box thumbnail-box">
278
+
279
+ <a class="thumbnail-a" href="' . get_the_permalink($p->id) . '"><img src="' . $thumbnail_img[0] . '" title="' . esc_attr($p->title) . '" class="rank_thumbnail" width="150" alt="thumbnail">
280
+
281
+ </a>
282
+
283
+ </div>
284
+
285
+ <div class="right-box">
286
+
287
+ <dl>
288
+
289
+ <dt>所属</dt>
290
+
291
+ <dd class="party-name"><a href="' . get_category_link( $cat_id ) . '">' . $cat_name . '</a></dd>
292
+
293
+ <dd>' . $tag_id . '</dd>
294
+
295
+ <dd class="region">'. $custom_region1 .''. $custom_region2 .'</dd>
296
+
297
+ </dl>
298
+
299
+ <p class="name"><a href="' . get_the_permalink($p->id) . '">'. $custom_name .'</a></p>
300
+
301
+ <div class="link-box">
302
+
303
+ <p><a href="' . get_home_url() . '/' . $cat_slug . '">&gt;地域詳細を見る</a></p>
304
+
305
+ <p><a href="' . get_the_permalink($p->id) . '">&gt;プロフィールを見る</a></p>
134
306
 
135
307
  </div>
136
308
 
137
- <div class="right-box">
138
-
139
- <dl>
140
-
141
- <dt>所属</dt>
142
-
143
- <dd class="party-name"><?php the_category(); ?></dd>
144
-
145
- <dd><?php the_tags('','',''); ?></dd>
146
-
147
- <dd class="region"><?php echo post_custom('region1'); echo post_custom('region2'); ?></dd>
148
-
149
- </dl>
150
-
151
- <p class="name"><a href="<?php the_permalink(); ?>"><?php echo post_custom('name'); ?></a></p>
152
-
153
- <div class="link-box">
154
-
155
- <?php $cat_slug = get_the_category(); $cat_slug = $cat_slug[0]; ?>
156
-
157
- <p><a href="<?php echo get_home_url(),"/",$cat_slug->category_nicename ?>">>所属地域の詳細を見る</a></p>
158
-
159
- <p><a href="<?php the_permalink(); ?>">>プロフィールを見る</a></p>
160
-
161
- </div>
162
-
163
- </div>
164
-
165
309
  </div>
166
310
 
311
+ </div>
312
+
167
- </article>
313
+ </article>
314
+
168
-
315
+ ';
316
+
317
+ return $output;
318
+
319
+ }
320
+
321
+ add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );
322
+
323
+ add_filter('redirect_canonical','my_disable_redirect_canonical');
324
+
325
+
326
+
327
+ function my_disable_redirect_canonical( $redirect_url ) {
328
+
329
+ if ( is_search() )
330
+
331
+ $redirect_url = false;
332
+
169
- <?php endwhile; ?>
333
+ return $redirect_url;
170
-
171
- <?php else : ?>
334
+
172
-
173
- <p class="notfound">該当者がいません。</p>
174
-
175
- <?php endif; ?>
176
-
177
- </div>
178
-
179
- <div class="s-page-nav cf">
180
-
181
- <?php
182
-
183
- $big = 999999999;
184
-
185
- echo paginate_links( array(
186
-
187
- 'base' => 'http://hogehoge/?s=' . $key . '%_%',
188
-
189
- 'format' => '&page=%#%',
190
-
191
- 'current' => max( 0, get_query_var('page') ),
192
-
193
- 'total' => $the_query->max_num_pages,
194
-
195
- 'end_size' => 5,
196
-
197
- 'type' => 'list',
198
-
199
- 'show_all' => 'false'
200
-
201
- ) );
335
+ }
202
-
203
- wp_reset_postdata();
336
+
204
-
337
+
338
+
205
- ?>
339
+ ?>
206
-
207
- </div>
208
-
209
- </div>
210
-
211
- </section>
212
-
213
- </div>
214
-
215
- <?php get_sidebar(); ?>
216
-
217
- </div>
218
-
219
- </div>
220
-
221
- <?php get_footer(); ?>
222
-
223
-
224
340
 
225
341
  ```
226
-
227
- ###試したこと
228
-
229
- ```
230
-
231
- function my_disable_redirect_canonical( $redirect_url ) {
232
-
233
- if ( is_search() )
234
-
235
- $redirect_url = false;
236
-
237
- return $redirect_url;
238
-
239
- }
240
-
241
- ```
242
-
243
- 上記をfunction.phpに加えると良いと説明しているサイトを見受けたため、入れてみましたが、何ら改善されませんでした。
244
-
245
- function.phpに関しても下記に掲載いたします。
246
-
247
- popularpostでの表示を意図通りにするため、function.phpに関しても下記のように書き加えています。
248
-
249
-
250
-
251
- ▼以下function.php全文▼
252
-
253
- ```
254
-
255
- <?php
256
-
257
- // アイキャッチ画像を有効にする。
258
-
259
- add_theme_support('post-thumbnails');
260
-
261
- //アイキャッチの自動トリミング設定
262
-
263
- if (function_exists('add_theme_support')) {
264
-
265
- add_theme_support('post-thumbnails');
266
-
267
- add_image_size( 'pc_single_thumbnails', 800, 500, true );
268
-
269
- add_image_size( 'pc_list_thumbnails', 608, 380, true );
270
-
271
- add_image_size( 'main_thumbnails', 480, 300, true );
272
-
273
- add_image_size( 'mobile_list_thumbnails', 240, 180, true );
274
-
275
- }
276
-
277
- //ここからポピュラーポストのカスタマイズ設定
278
-
279
- function my_custom_single_popular_post( $post_html, $p, $instance ){
280
-
281
- $thumbnail_id = get_post_thumbnail_id( $p->id);
282
-
283
- $thumbnail_img = wp_get_attachment_image_src( $thumbnail_id, 'main_thumbnails' );
284
-
285
- $post_cat=get_the_category( $p->id);
286
-
287
- $cat_id=$post_cat[0]->cat_ID;
288
-
289
- $cat_name=$post_cat[0]->cat_name;
290
-
291
- $cat = get_the_category();
292
-
293
- $cat = $cat[0];
294
-
295
- $cat_slug = $post_cat[0]->category_nicename;
296
-
297
- $post_tag=get_the_tags( $p->id);
298
-
299
- $tag_id=$post_tag[0]->name;
300
-
301
- $custom_name = get_post_meta($p->id, 'name', true);
302
-
303
- $custom_region1 = get_post_meta($p->id, 'region1', true);
304
-
305
- $custom_region2 = get_post_meta($p->id, 'region2', true);
306
-
307
- $custom_id= $p->id;
308
-
309
- //$excerpt = get_post_field( post_content, $p->id, display );
310
-
311
- $output = '
312
-
313
- <article>
314
-
315
- <div class="list-block cf">
316
-
317
- <div class="left-box thumbnail-box">
318
-
319
- <a class="thumbnail-a" href="' . get_the_permalink($p->id) . '"><img src="' . $thumbnail_img[0] . '" title="' . esc_attr($p->title) . '" class="rank_thumbnail" width="150" alt="thumbnail">
320
-
321
- </a>
322
-
323
- </div>
324
-
325
- <div class="right-box">
326
-
327
- <dl>
328
-
329
- <dt>所属</dt>
330
-
331
- <dd class="party-name"><a href="' . get_category_link( $cat_id ) . '">' . $cat_name . '</a></dd>
332
-
333
- <dd>' . $tag_id . '</dd>
334
-
335
- <dd class="region">'. $custom_region1 .''. $custom_region2 .'</dd>
336
-
337
- </dl>
338
-
339
- <p class="name"><a href="' . get_the_permalink($p->id) . '">'. $custom_name .'</a></p>
340
-
341
- <div class="link-box">
342
-
343
- <p><a href="' . get_home_url() . '/' . $cat_slug . '">&gt;所属地域の詳細を見る</a></p>
344
-
345
- <p><a href="' . get_the_permalink($p->id) . '">&gt;プロフィールを見る</a></p>
346
-
347
- </div>
348
-
349
- </div>
350
-
351
- </div>
352
-
353
- </article>
354
-
355
- ';
356
-
357
- return $output;
358
-
359
- }
360
-
361
- add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );
362
-
363
- add_filter('redirect_canonical','my_disable_redirect_canonical');
364
-
365
-
366
-
367
- function my_disable_redirect_canonical( $redirect_url ) {
368
-
369
- if ( is_search() )
370
-
371
- $redirect_url = false;
372
-
373
- return $redirect_url;
374
-
375
- }
376
-
377
- ?>
378
-
379
- ```

1

加筆修正を行いました。

2016/11/20 11:08

投稿

happyturn
happyturn

スコア12

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,9 @@
10
10
 
11
11
  ページャーの2ページ目をクリックすると、
12
12
 
13
- http://hogehoge/page/2/?s=検索語句のURLに飛び、
13
+ 「**http://hogehoge/page/2/?s=検索語句**」
14
+
15
+ のURLに飛び、
14
16
 
15
17
  どうしてもNOTFOUNDになり困り果てていました。
16
18
 
@@ -18,11 +20,19 @@
18
20
 
19
21
  そこでいろいろと調べて、調整したところ、
20
22
 
21
- http://hogehoge/?s=検索語句&page=2
23
+ 「**http://hogehoge/?s=検索語句&page=2**」
22
24
 
23
25
  というように飛ぶ先のURLを変更させることで、NOTFOUNDにはならず、ちゃんと検索結果が表示されるようになりました。
24
26
 
27
+
28
+
29
+ **しかし、解決したかに見えたのですが、そこからはまることになりました。
30
+
31
+ よく見ると、2ページ目以降の全てのページがどういうわけか1ページ目と同じ内容が表示されるようになりました**。
32
+
33
+
34
+
25
- 解決したかに見えたのですが、よく見ると、2ページ目以降の全てのページがどういうわけか1ページ目と同じ内容が表示されます。 何か初歩的なミスをしているのか、どこがどう間違っているのか、なんなのれこれ数日悩んでおり完全にお手上げ状態です。
35
+ 何か初歩的なミスをしているのか、どこがどう間違っているのか、かれこれ数日悩んでおり完全にお手上げ状態です。
26
36
 
27
37
  検索に関しては県名、地域、詳細地域というようにカスタムフィールドで三点設定(region0,region1,region2)されており、地図上からクリックをして該当地域に所属する人物を検索結果として表示させるという物です。
28
38