質問編集履歴
9
新しいphpコードを使いました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,8 +10,258 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
※参考になるphpコードがありましたが、コードの内容がイマイチ分かりません。下記に掲載します。
|
14
|
+
|
15
|
+
質問は二つです。
|
16
|
+
|
17
|
+
絞り込み検索をよりわかりやすくするのに、どういうコードを書けばいいですか?(例)◯◯◯(場所)と◯◯◯(料理のジャンル) 二つのキーワードで絞り込み検索を行う
|
18
|
+
|
19
|
+
また、料理店だけの情報サイトにしたいのですが、下記のコードに何を書けばいいですか? (例)食べログ
|
20
|
+
|
21
|
+
|
22
|
+
|
13
23
|
```PHP
|
14
24
|
|
25
|
+
> <?php
|
26
|
+
|
27
|
+
> /**
|
28
|
+
|
29
|
+
> * Template Name: Miyagirestaurant
|
30
|
+
|
31
|
+
> *
|
32
|
+
|
33
|
+
> */
|
34
|
+
|
35
|
+
> get_header();
|
36
|
+
|
37
|
+
> /*
|
38
|
+
|
39
|
+
> * 01:北海道
|
40
|
+
|
41
|
+
> 02:青森県 03:岩手県 04:宮城県 05:秋田県 06:山形県 07:福島県
|
42
|
+
|
43
|
+
> 08:茨城県 09:栃木県 10:群馬県 11:埼玉県 12:千葉県 13:東京都 14:神奈川県
|
44
|
+
|
45
|
+
> 15:新潟県 16:富山県 17:石川県 18:福井県 19:山梨県 20:長野県
|
46
|
+
|
47
|
+
> 21:岐阜県 22:静岡県 23:愛知県 24:三重県
|
48
|
+
|
49
|
+
> 25:滋賀県 26:京都府 27:大阪府 28:兵庫県 29:奈良県 30:和歌山県
|
50
|
+
|
51
|
+
> 31:鳥取県 32:島根県 33:岡山県 34:広島県 35:山口県
|
52
|
+
|
53
|
+
> 36:徳島県 37:香川県 38:愛媛県 39:高知県
|
54
|
+
|
55
|
+
> 40:福岡県 41:佐賀県 42:長崎県 43:熊本県 44:大分県 45:宮崎県 46:鹿児島県 47:沖縄県
|
56
|
+
|
57
|
+
> */
|
58
|
+
|
59
|
+
> ?>
|
60
|
+
|
61
|
+
> <form method="GET">
|
62
|
+
|
63
|
+
> <select name="my_filter" id="my_filter">
|
64
|
+
|
65
|
+
> <option value="04100"> 宮城県 仙台市(全体)</option>
|
66
|
+
|
67
|
+
> <option value="04101"> 宮城県 仙台市 青葉区</option>
|
68
|
+
|
69
|
+
> <option value="04102"> 宮城県 仙台市 宮城野区</option>
|
70
|
+
|
71
|
+
> <option value="04103"> 宮城県 仙台市 若林区</option>
|
72
|
+
|
73
|
+
> <option value="04104"> 宮城県 仙台市 太白区</option>
|
74
|
+
|
75
|
+
> <option value="04105"> 宮城県 仙台市 泉区</option>
|
76
|
+
|
77
|
+
> <option value="04202"> 宮城県 石巻市</option>
|
78
|
+
|
79
|
+
> <option value="04203"> 宮城県 塩竈市</option>
|
80
|
+
|
81
|
+
> <option value="04205"> 宮城県 気仙沼市</option>
|
82
|
+
|
83
|
+
> <option value="04206"> 宮城県 白石市</option>
|
84
|
+
|
85
|
+
> <option value="04207"> 宮城県 名取市</option>
|
86
|
+
|
87
|
+
> <option value="04208"> 宮城県 角田市</option>
|
88
|
+
|
89
|
+
> <option value="04209"> 宮城県 多賀城市</option>
|
90
|
+
|
91
|
+
> <option value="04211"> 宮城県 岩沼市</option>
|
92
|
+
|
93
|
+
> <option value="04212"> 宮城県 登米市</option>
|
94
|
+
|
95
|
+
> <option value="04213"> 宮城県 栗原市</option>
|
96
|
+
|
97
|
+
> <option value="04214"> 宮城県 東松島市</option>
|
98
|
+
|
99
|
+
> <option value="04215"> 宮城県 大崎市</option>
|
100
|
+
|
101
|
+
> <option value="04301"> 宮城県 刈田郡 蔵王町</option>
|
102
|
+
|
103
|
+
> <option value="04302"> 宮城県 刈田郡 七ヶ宿町</option>
|
104
|
+
|
105
|
+
> <option value="04321"> 宮城県 柴田郡 大河原町</option>
|
106
|
+
|
107
|
+
> <option value="04322"> 宮城県 柴田郡 村田町</option>
|
108
|
+
|
109
|
+
> <option value="04323"> 宮城県 柴田郡 柴田町</option>
|
110
|
+
|
111
|
+
> <option value="04324"> 宮城県 柴田郡 川崎町</option>
|
112
|
+
|
113
|
+
> <option value="04341"> 宮城県 伊具郡 丸森町</option>
|
114
|
+
|
115
|
+
> <option value="04361"> 宮城県 亘理郡 亘理町</option>
|
116
|
+
|
117
|
+
> <option value="04362"> 宮城県 亘理郡 山元町</option>
|
118
|
+
|
119
|
+
> <option value="04401"> 宮城県 宮城郡 松島町</option>
|
120
|
+
|
121
|
+
> <option value="04404"> 宮城県 宮城郡 七ヶ浜町</option>
|
122
|
+
|
123
|
+
> <option value="04406"> 宮城県 宮城郡 利府町</option>
|
124
|
+
|
125
|
+
> <option value="04421"> 宮城県 黒川郡 大和町</option>
|
126
|
+
|
127
|
+
> <option value="04422"> 宮城県 黒川郡 大郷町</option>
|
128
|
+
|
129
|
+
> <option value="04423"> 宮城県 黒川郡 富谷町</option>
|
130
|
+
|
131
|
+
> <option value="04424"> 宮城県 黒川郡 大衡村</option>
|
132
|
+
|
133
|
+
> <option value="04444"> 宮城県 加美郡 色麻町</option>
|
134
|
+
|
135
|
+
> <option value="04445"> 宮城県 加美郡 加美町</option>
|
136
|
+
|
137
|
+
> <option value="04501"> 宮城県 遠田郡 涌谷町</option>
|
138
|
+
|
139
|
+
> <option value="04505"> 宮城県 遠田郡 美里町</option>
|
140
|
+
|
141
|
+
> <option value="04581"> 宮城県 牡鹿郡 女川町</option>
|
142
|
+
|
143
|
+
> <option value="04606"> 宮城県 本吉郡 南三陸町</option>
|
144
|
+
|
145
|
+
> </select>
|
146
|
+
|
147
|
+
> <input type="submit" value="絞り込み" />
|
148
|
+
|
149
|
+
> </form>
|
150
|
+
|
151
|
+
> <?php
|
152
|
+
|
153
|
+
> if ( isset( $_GET[ 'my_filter' ] ) && preg_match( '![0-9]{5}!', $_GET[ 'my_filter' ] ) ) {
|
154
|
+
|
155
|
+
> $area = $_GET[ 'my_filter' ];
|
156
|
+
|
157
|
+
> } else {
|
158
|
+
|
159
|
+
> $area = '04100';
|
160
|
+
|
161
|
+
> }
|
162
|
+
|
163
|
+
> if ( isset( $_GET[ 'my_page' ] ) && is_numeric( $_GET[ 'my_page' ] ) ) {
|
164
|
+
|
165
|
+
>
|
166
|
+
|
167
|
+
> $my_page = absint( $_GET[ 'my_page' ] );
|
168
|
+
|
169
|
+
> } else {
|
170
|
+
|
171
|
+
> $my_page = 1;
|
172
|
+
|
173
|
+
> }
|
174
|
+
|
175
|
+
>
|
176
|
+
|
177
|
+
> $id = '私のid';
|
178
|
+
|
179
|
+
> $item_per_page = 50;
|
180
|
+
|
181
|
+
> $start = ( $my_page - 1) * $item_per_page + 1;
|
182
|
+
|
183
|
+
> $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid=' . $id . '&ac=' . $area .'&results=' . $item_per_page . '&start=' . $start . '&detail=full';
|
184
|
+
|
185
|
+
> $xml = simplexml_load_file( $url );
|
186
|
+
|
187
|
+
> $total_count = $xml->ResultInfo->Total;
|
188
|
+
|
189
|
+
>
|
190
|
+
|
191
|
+
> echo '<table class="left">';
|
192
|
+
|
193
|
+
> echo '<caption>' . $start . '件目から' . $item_per_page . '件 表示中 / 総件数 ' . $total_count . '</caption>';
|
194
|
+
|
195
|
+
> echo '<style scoped>.paging, table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}form{text-align:center;padding:2em;}
|
196
|
+
|
197
|
+
> .page-link{padding:1em;margin:.3em;display:inline-block;width:3em;border:1px solid #ccc;word-wrap:normal;}h2{text-align:center;margin:2em 0;}</style>';
|
198
|
+
|
199
|
+
>
|
200
|
+
|
201
|
+
> $html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></tr>';
|
202
|
+
|
203
|
+
> $i = 1;
|
204
|
+
|
205
|
+
>
|
206
|
+
|
207
|
+
> foreach ( $xml->Feature as $key => $item ) {
|
208
|
+
|
209
|
+
>
|
210
|
+
|
211
|
+
> printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1 );
|
212
|
+
|
213
|
+
>
|
214
|
+
|
215
|
+
> $i++;
|
216
|
+
|
217
|
+
> }
|
218
|
+
|
219
|
+
> echo '</table>';
|
220
|
+
|
221
|
+
> ?>
|
222
|
+
|
223
|
+
> <h2>Navigation</h2>
|
224
|
+
|
225
|
+
> <div class="paging" >
|
226
|
+
|
227
|
+
> <?php
|
228
|
+
|
229
|
+
> $pages = ceil( $total_count / $item_per_page );
|
230
|
+
|
231
|
+
>
|
232
|
+
|
233
|
+
> for ( $i = 1; $i < $pages + 1; $i++ ) {
|
234
|
+
|
235
|
+
>
|
236
|
+
|
237
|
+
> printf( '<span class="page-link"><a href="%1$s">%2$s</a></span> ', get_permalink() . '?my_filter=' . $area . '&my_page=' . $i, $i );
|
238
|
+
|
239
|
+
> }
|
240
|
+
|
241
|
+
> ?>
|
242
|
+
|
243
|
+
> </div>
|
244
|
+
|
245
|
+
> <?php
|
246
|
+
|
247
|
+
> get_footer();
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
```PHP
|
264
|
+
|
15
265
|
<?php
|
16
266
|
|
17
267
|
/*
|
8
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
一応、下記のphpコードで店舗情報を一列ごとに並べることはできましたが、仕組みがわかりません。
|
6
6
|
|
7
|
+
※僕の思い通りにならないと言っていることとは、取得した店舗情報を『東京都港区◯◯◯/住所◯◯◯/電話番号◯◯◯/◯◯◯駅』という風に一行に表示したい、APIの情報がたくさん欲しいです。
|
8
|
+
|
7
|
-
|
9
|
+
また作成したphpファイルの中身は下記に掲載しました。
|
8
10
|
|
9
11
|
|
10
12
|
|
7
プライバシー
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
$id = '
|
43
|
+
$id = '私のid';
|
44
44
|
|
45
45
|
$area = 13;
|
46
46
|
|
6
php
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,70 +8,74 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
```PHP
|
12
12
|
|
13
|
-
|
13
|
+
<?php
|
14
14
|
|
15
|
-
|
15
|
+
/*
|
16
16
|
|
17
|
-
|
17
|
+
Template Name: tokyorestaurantinfo
|
18
18
|
|
19
|
-
|
19
|
+
*/
|
20
20
|
|
21
|
-
>
|
21
|
+
?>
|
22
22
|
|
23
|
-
> <!DOCTYPE html>
|
24
23
|
|
25
|
-
> <html lang="ja">
|
26
24
|
|
27
|
-
|
25
|
+
<!DOCTYPE html>
|
28
26
|
|
29
|
-
|
27
|
+
<html lang="ja">
|
30
28
|
|
31
|
-
|
29
|
+
<head>
|
32
30
|
|
33
|
-
|
31
|
+
<meta charset="UTF-8">
|
34
32
|
|
35
|
-
>
|
33
|
+
<title>東京の店舗情報</title>
|
36
34
|
|
37
|
-
|
35
|
+
<head>
|
38
36
|
|
39
|
-
>
|
37
|
+
<body>
|
40
38
|
|
41
|
-
|
39
|
+
<?php
|
42
40
|
|
43
|
-
|
41
|
+
|
44
42
|
|
45
|
-
|
43
|
+
$id = 'dj0zaiZpPWZKMnpnYUN0WEdVcSZzPWNvbnN1bWVyc2VjcmV0Jng9NGM-';
|
46
44
|
|
47
|
-
|
45
|
+
$area = 13;
|
48
46
|
|
49
|
-
|
47
|
+
$ct = '01';
|
50
48
|
|
51
|
-
|
49
|
+
$start = '1';
|
52
50
|
|
53
|
-
|
51
|
+
$url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid='. $id .'&ac='. $area .'&gc='. $ct .'&results=100&start='. $start .'&detail=full';
|
54
52
|
|
55
|
-
>
|
56
53
|
|
57
|
-
> echo '<table class="left">';
|
58
54
|
|
59
|
-
|
55
|
+
$xml = simplexml_load_file( $url );
|
60
56
|
|
61
|
-
> $html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></td>%8$s</td></tr>';
|
62
57
|
|
63
|
-
>
|
64
58
|
|
65
|
-
|
59
|
+
echo '<table class="left">';
|
66
60
|
|
67
|
-
>
|
61
|
+
echo '<style scoped>table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}</style>';
|
68
62
|
|
69
|
-
|
63
|
+
$html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></td>%8$s</td></tr>';
|
70
64
|
|
71
|
-
> }
|
72
65
|
|
73
|
-
> echo '</table>';
|
74
66
|
|
75
|
-
>
|
67
|
+
foreach ( $xml->Feature as $item ) {
|
76
68
|
|
77
|
-
|
69
|
+
|
70
|
+
|
71
|
+
printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1,$item->Property->Image1 );
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
echo '</table>';
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
?>
|
80
|
+
|
81
|
+
```
|
5
php
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
wordpress
|
1
|
+
wordpressにyahooのapiの情報(yahooのローカルリサーチ)を表示させるやり方。
|
test
CHANGED
File without changes
|
4
php
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ここで質問ですが、apiから多くの情報を得るにはphpにどういうコードを付け足すべきですか?また、APIの情報を綺麗に明確に表示するにはどういうコードを書けばいいですか?
|
4
4
|
|
5
|
-
|
5
|
+
一応、下記のphpコードで店舗情報を一列ごとに並べることはできましたが、仕組みがわかりません。
|
6
6
|
|
7
7
|
※作成したphpファイルの中身は下記に掲載しました。
|
8
8
|
|
3
php
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
>
|
40
40
|
|
41
|
-
> $id = '
|
41
|
+
> $id = '私のid';
|
42
42
|
|
43
43
|
> $area = 13;
|
44
44
|
|
2
php
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,70 +8,70 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
><?php
|
11
|
+
> <?php
|
12
12
|
|
13
|
-
/*
|
13
|
+
> /*
|
14
14
|
|
15
|
-
Template Name: tokyorestaurantinfo
|
15
|
+
> Template Name: tokyorestaurantinfo
|
16
16
|
|
17
|
-
*/
|
17
|
+
> */
|
18
18
|
|
19
|
-
?>
|
19
|
+
> ?>
|
20
20
|
|
21
|
+
>
|
21
22
|
|
23
|
+
> <!DOCTYPE html>
|
22
24
|
|
23
|
-
<
|
25
|
+
> <html lang="ja">
|
24
26
|
|
25
|
-
<h
|
27
|
+
> <head>
|
26
28
|
|
27
|
-
<he
|
29
|
+
> <meta charset="UTF-8">
|
28
30
|
|
29
|
-
<
|
31
|
+
> <title>東京の店舗情報</title>
|
30
32
|
|
31
|
-
|
33
|
+
> <head>
|
32
34
|
|
33
|
-
<
|
35
|
+
> <body>
|
34
36
|
|
35
|
-
<
|
37
|
+
> <?php
|
36
38
|
|
37
|
-
|
39
|
+
>
|
38
40
|
|
39
|
-
|
41
|
+
> $id = 'dj0zaiZpPWZKMnpnYUN0WEdVcSZzPWNvbnN1bWVyc2VjcmV0Jng9NGM-';
|
40
42
|
|
41
|
-
$
|
43
|
+
> $area = 13;
|
42
44
|
|
43
|
-
$
|
45
|
+
> $ct = '01';
|
44
46
|
|
45
|
-
$
|
47
|
+
> $start = '1';
|
46
48
|
|
47
|
-
$star
|
49
|
+
> $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid='. $id .'&ac='. $area .'&gc='. $ct .'&results=100&start='. $start .'&detail=full';
|
48
50
|
|
49
|
-
|
51
|
+
>
|
50
52
|
|
53
|
+
> $xml = simplexml_load_file( $url );
|
51
54
|
|
55
|
+
>
|
52
56
|
|
53
|
-
|
57
|
+
> echo '<table class="left">';
|
54
58
|
|
59
|
+
> echo '<style scoped>table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}</style>';
|
55
60
|
|
61
|
+
> $html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></td>%8$s</td></tr>';
|
56
62
|
|
57
|
-
|
63
|
+
>
|
58
64
|
|
59
|
-
ech
|
65
|
+
> foreach ( $xml->Feature as $item ) {
|
60
66
|
|
61
|
-
|
67
|
+
>
|
62
68
|
|
69
|
+
> printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1,$item->Property->Image1 );
|
63
70
|
|
71
|
+
> }
|
64
72
|
|
65
|
-
|
73
|
+
> echo '</table>';
|
66
74
|
|
75
|
+
>
|
67
76
|
|
68
|
-
|
69
|
-
printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1,$item->Property->Image1 );
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
echo '</table>';
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
?>引用テキスト
|
77
|
+
> ?>
|
1
php
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
>
|
11
|
+
><?php
|
12
12
|
|
13
13
|
/*
|
14
14
|
|
@@ -74,4 +74,4 @@
|
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
-
?>
|
77
|
+
?>引用テキスト
|