質問編集履歴

1

コードの追加

2017/04/15 08:04

投稿

Lyo
Lyo

スコア12

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,375 @@
81
81
 
82
82
 
83
83
  原因のわかる方、宜しくお願いいたします。
84
+
85
+
86
+
87
+ 追記
88
+
89
+
90
+
91
+ オリジナルテーマです。
92
+
93
+
94
+
95
+ サイドバー
96
+
97
+ ```UTF-8
98
+
99
+ <?php
100
+
101
+ /**
102
+
103
+ * The template for displaying the sidebar
104
+
105
+ * @package WordPress
106
+
107
+ */
108
+
109
+ ?>
110
+
111
+ <div id="nav" class="sidebar2">
112
+
113
+ <div class="side_inr1">
114
+
115
+ <div class="side_title1">
116
+
117
+ <img src="">
118
+
119
+ <div class="blog">
120
+
121
+ <?php query_posts('posts_per_page=5'); ?>
122
+
123
+ <?php if (have_posts()):while(have_posts()):the_post(); ?>
124
+
125
+
126
+
127
+ <a href="<?php echo get_permalink(); ?>"><h2><p><?php the_title(); ?></p></h2></a>
128
+
129
+
130
+
131
+ <?php endwhile; endif; ?>
132
+
133
+ </div>
134
+
135
+ </div>
136
+
137
+ </div>
138
+
139
+ <div class="side_inr2">
140
+
141
+ <div class="side_title2">
142
+
143
+ <img src="">
144
+
145
+ </div>
146
+
147
+ <img src="">
148
+
149
+ <img src="">
150
+
151
+ </div>
152
+
153
+ <div class="side_inr3">
154
+
155
+ <div class="side_title3">
156
+
157
+ <img src="">
158
+
159
+ </div>
160
+
161
+ <a href=""></a>
162
+
163
+ <a href=""></a>
164
+
165
+ <a href=""></a>
166
+
167
+ <a href="/contact-2/"><img src=""></a>
168
+
169
+ </div>
170
+
171
+ <div class="side_fb">
172
+
173
+ <iframe src=""></iframe>
174
+
175
+ </div>
176
+
177
+ </div>
178
+
179
+ ```
180
+
181
+
182
+
183
+ ヘッダー
184
+
185
+ ```UTF-8
186
+
187
+ <?php
188
+
189
+ /**
190
+
191
+ * The template for displaying the header
192
+
193
+ * @package WordPress
194
+
195
+ */
196
+
197
+ ?>
198
+
199
+ <!DOCTYPE html>
200
+
201
+ <html>
202
+
203
+ <head>
204
+
205
+ <meta charset="utf-8">
206
+
207
+ <meta name="keywords" content="">
208
+
209
+ <meta name="description" content="">
210
+
211
+ <title></title>
212
+
213
+ <?php wp_head(); ?>
214
+
215
+ <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
216
+
217
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
218
+
219
+ <link href="<?php echo get_stylesheet_directory_uri() ?>/style.css" rel="stylesheet" type="text/css" media="all">
220
+
221
+ </head>
222
+
223
+
224
+
225
+ <body>
226
+
227
+ <header>
228
+
229
+ <a href=""><h1><img class="logo2" src=""></h1></a>
230
+
231
+ </div>
232
+
233
+
234
+
235
+ </header>
236
+
237
+ ```
238
+
239
+ footer.php
240
+
241
+
242
+
243
+ ```UTF-8
244
+
245
+ <?php
246
+
247
+ /**
248
+
249
+ * The template for displaying the footer
250
+
251
+ * @package WordPress
252
+
253
+ */
254
+
255
+ ?>
256
+
257
+ <div class="cb"></div>
258
+
259
+ </div>
260
+
261
+
262
+
263
+
264
+
265
+ <?php wp_footer(); ?>
266
+
267
+ </body>
268
+
269
+ </html>
270
+
271
+
272
+
273
+ ```
274
+
275
+
276
+
277
+ function.php
278
+
279
+ ```UTF-8
280
+
281
+ <?php
282
+
283
+
284
+
285
+ // ウィジェット
286
+
287
+ register_sidebar();
288
+
289
+
290
+
291
+ add_theme_support( 'post-thumbnails', array( 'post' ) );
292
+
293
+ set_post_thumbnail_size( 100, 100, true );
294
+
295
+
296
+
297
+
298
+
299
+ function new_excerpt_more($post) {
300
+
301
+ return '<a href="'. get_permalink($post->ID) . '">' . '...続きを読む' . '</a>';
302
+
303
+ }
304
+
305
+ add_filter('excerpt_more', 'new_excerpt_more');
306
+
307
+
308
+
309
+
310
+
311
+ ?>
312
+
313
+ <?php
314
+
315
+ // functions.phpに以下を追記
316
+
317
+ add_action('admin_menu', 'add_custom_fields');
318
+
319
+ add_action('save_post', 'save_custom_fields');
320
+
321
+
322
+
323
+ // 記事ページと固定ページでカスタムフィールドを表示
324
+
325
+ function add_custom_fields() {
326
+
327
+ add_meta_box( 'my_sectionid', 'カスタムフィールド', 'my_custom_fields', 'post');
328
+
329
+ add_meta_box( 'my_sectionid', 'カスタムフィールド', 'my_custom_fields', 'page');
330
+
331
+ }
332
+
333
+
334
+
335
+ function my_custom_fields() {
336
+
337
+ global $post;
338
+
339
+ $keywords = get_post_meta($post->ID,'keywords',true);
340
+
341
+ $description = get_post_meta($post->ID,'description',true);
342
+
343
+
344
+
345
+ echo '<p>キーワード(半角カンマ区切り)<br>';
346
+
347
+ echo '<input type="text" name="keywords" value="'.esc_html($keywords).'" size="60" /></p>';
348
+
349
+
350
+
351
+ echo '<p>ページの説明(description)160文字以内<br>';
352
+
353
+ echo '<input type="text" style="width: 600px;height: 40px;" name="description" value="'.esc_html($description).'" maxlength="160" /></p>';
354
+
355
+ }
356
+
357
+
358
+
359
+ // カスタムフィールドの値を保存
360
+
361
+ function save_custom_fields( $post_id ) {
362
+
363
+ if(!empty($_POST['keywords']))
364
+
365
+ update_post_meta($post_id, 'keywords', $_POST['keywords'] );
366
+
367
+ else delete_post_meta($post_id, 'keywords');
368
+
369
+
370
+
371
+ if(!empty($_POST['description']))
372
+
373
+ update_post_meta($post_id, 'description', $_POST['description'] );
374
+
375
+ else delete_post_meta($post_id, 'description');
376
+
377
+ }
378
+
379
+
380
+
381
+ function my_description() {
382
+
383
+
384
+
385
+ // カスタムフィールドの値を読み込む
386
+
387
+ $custom = get_post_custom();
388
+
389
+ if(!empty( $custom['keywords'][0])) {
390
+
391
+ $keywords = $custom['keywords'][0];
392
+
393
+ }
394
+
395
+ if(!empty( $custom['description'][0])) {
396
+
397
+ $description = $custom['description'][0];
398
+
399
+ }
400
+
401
+ ?>
402
+
403
+ <?php if(is_home()): // トップページ ?>
404
+
405
+ <meta name="robots" content="index, follow" />
406
+
407
+ <meta name="keywords" content="トップページに表示させるkeywords(半角カンマ区切り)">
408
+
409
+ <meta name="description" content="トップページに表示させるdescription" />
410
+
411
+ <?php elseif(is_single()): // 記事ページ ?>
412
+
413
+ <meta name="robots" content="index, follow" />
414
+
415
+ <meta name="keywords" content="<?php echo $keywords ?>">
416
+
417
+ <meta name="description" content="<?php echo $description ?>">
418
+
419
+ <?php elseif(is_page()): // 固定ページ ?>
420
+
421
+ <meta name="robots" content="index, follow" />
422
+
423
+ <meta name="keywords" content="<?php echo $keywords ?>">
424
+
425
+ <meta name="description" content="<?php echo $description ?>">
426
+
427
+ <?php elseif (is_category()): // カテゴリーページ ?>
428
+
429
+ <meta name="robots" content="index, follow" />
430
+
431
+ <meta name="description" content="<?php single_cat_title(); ?>の記事一覧" />
432
+
433
+ <?php elseif (is_tag()): // タグページ ?>
434
+
435
+ <meta name="robots" content="noindex, follow" />
436
+
437
+ <meta name="description" content="<?php single_tag_title("", true); ?>の記事一覧" />
438
+
439
+ <?php elseif(is_404()): // 404ページ ?>
440
+
441
+ <meta name="robots" content="noindex, follow" />
442
+
443
+ <title><?php echo 'お探しのページが見つかりませんでした'; ?></title>
444
+
445
+ <?php else: // その他ページ ?>
446
+
447
+ <meta name="robots" content="noindex, follow" />
448
+
449
+ <?php endif; ?>
450
+
451
+ <?php
452
+
453
+ }
454
+
455
+ ```