質問編集履歴
6
こういうイメージで作っています
test
CHANGED
File without changes
|
test
CHANGED
@@ -437,3 +437,49 @@
|
|
437
437
|
|
438
438
|
|
439
439
|
昨日教えていただいたコードでrecent_posts.phpの"http://投稿一覧のURL"において、http://localhost/wordpress/blog/とすると、そのページにしか遷移しないので、それをlocalhost/wordpress/blog/2/やlocalhost/wordpress/blog/3/といった風にphpのコードを埋めてページ遷移させたいです。よろしくお願いします。
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
recent_posts.php
|
444
|
+
|
445
|
+
```php
|
446
|
+
|
447
|
+
<?php
|
448
|
+
|
449
|
+
$args = array(
|
450
|
+
|
451
|
+
'post_type' => 'post',
|
452
|
+
|
453
|
+
'posts_per_page' => 5,
|
454
|
+
|
455
|
+
);
|
456
|
+
|
457
|
+
$the_query = new WP_Query( $args );
|
458
|
+
|
459
|
+
if ( $the_query->have_posts() ):
|
460
|
+
|
461
|
+
while ( $the_query->have_posts() ):
|
462
|
+
|
463
|
+
$the_query->the_post();
|
464
|
+
|
465
|
+
$category = get_the_category();
|
466
|
+
|
467
|
+
$category_link = get_category_link( $category[0]->term_id );
|
468
|
+
|
469
|
+
?>
|
470
|
+
|
471
|
+
<?php $p_slug = get_page_uri(get_the_ID()); ?>
|
472
|
+
|
473
|
+
<p><a href="<?php echo $category_link.'#'.$p_slug; ?>" ><?php the_title(); ?></a></p>
|
474
|
+
|
475
|
+
<?php
|
476
|
+
|
477
|
+
endwhile;
|
478
|
+
|
479
|
+
endif;
|
480
|
+
|
481
|
+
wp_reset_query();
|
482
|
+
|
483
|
+
```
|
484
|
+
|
485
|
+
とやるとリンクさきのidにページ内リンクできました。
|
5
わかりにくい説明だったので修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -433,3 +433,7 @@
|
|
433
433
|
|
434
434
|
|
435
435
|
関係のないテンプレートの表記を削除しました。
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
昨日教えていただいたコードでrecent_posts.phpの"http://投稿一覧のURL"において、http://localhost/wordpress/blog/とすると、そのページにしか遷移しないので、それをlocalhost/wordpress/blog/2/やlocalhost/wordpress/blog/3/といった風にphpのコードを埋めてページ遷移させたいです。よろしくお願いします。
|
4
いらないテンプレートを削除しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -246,138 +246,120 @@
|
|
246
246
|
|
247
247
|
|
248
248
|
|
249
|
+
|
250
|
+
|
249
|
-
fo
|
251
|
+
function.php
|
250
252
|
|
251
253
|
```php
|
252
254
|
|
255
|
+
<?php
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
add_theme_support( 'custom-header' );
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
add_theme_support('menus');
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
register_sidebar(
|
268
|
+
|
269
|
+
array(
|
270
|
+
|
253
|
-
<div
|
271
|
+
before_widget => '<div class="widget">',
|
272
|
+
|
254
|
-
|
273
|
+
after_widget => '</div>',
|
274
|
+
|
275
|
+
before_title => '<h3>',
|
276
|
+
|
277
|
+
after_title => '</h3>',
|
278
|
+
|
279
|
+
)
|
280
|
+
|
281
|
+
);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
add_theme_support('post-thumbnails');
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
$cssdir = get_stylesheet_directory_uri();
|
290
|
+
|
255
|
-
|
291
|
+
wp_enqueue_script( 'theme-script', $cssdir.'/script.php', array('jquery'));
|
292
|
+
|
293
|
+
|
294
|
+
|
256
|
-
|
295
|
+
// ウィジェットでショートコードを使えるようにする
|
296
|
+
|
297
|
+
add_filter( 'widget_text', 'do_shortcode' );
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
// 任意のPHPファイルをショートコード化して扱えるようにする
|
302
|
+
|
303
|
+
function php_shortcode( $params = array() ) {
|
304
|
+
|
305
|
+
extract( shortcode_atts( array(
|
306
|
+
|
257
|
-
|
307
|
+
'file' => 'default'
|
308
|
+
|
258
|
-
|
309
|
+
), $params ));
|
310
|
+
|
311
|
+
ob_start();
|
312
|
+
|
313
|
+
include( get_template_directory() . "/$file.php" );
|
314
|
+
|
259
|
-
|
315
|
+
return ob_get_clean();
|
316
|
+
|
260
|
-
|
317
|
+
}
|
318
|
+
|
261
|
-
|
319
|
+
add_shortcode( 'my_php', 'php_shortcode' );
|
262
|
-
|
320
|
+
|
321
|
+
|
322
|
+
|
263
|
-
|
323
|
+
?>
|
264
|
-
|
265
|
-
|
324
|
+
|
266
|
-
|
267
|
-
```
|
325
|
+
```
|
268
|
-
|
326
|
+
|
269
|
-
|
327
|
+
recent_posts.php
|
270
328
|
|
271
329
|
```php
|
272
330
|
|
273
331
|
<?php
|
274
332
|
|
275
|
-
|
276
|
-
|
277
|
-
add_theme_support( 'custom-header' );
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
add_theme_support('menus');
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
register_sidebar(
|
286
|
-
|
287
|
-
|
333
|
+
$args = array(
|
288
|
-
|
289
|
-
|
334
|
+
|
290
|
-
|
291
|
-
after_widget => '</div>',
|
292
|
-
|
293
|
-
before_title => '<h3>',
|
294
|
-
|
295
|
-
|
335
|
+
'post_type' => 'post', //ポストタイプ
|
296
|
-
|
336
|
+
|
297
|
-
|
337
|
+
'posts_per_page' => 5, //表示件数
|
298
|
-
|
338
|
+
|
299
|
-
);
|
339
|
+
);
|
300
|
-
|
301
|
-
|
302
|
-
|
340
|
+
|
303
|
-
|
341
|
+
$the_query = new WP_Query( $args );
|
342
|
+
|
304
|
-
|
343
|
+
if ( $the_query->have_posts() ):
|
305
|
-
|
306
|
-
|
344
|
+
|
307
|
-
|
345
|
+
while ( $the_query->have_posts() ):
|
308
|
-
|
309
|
-
|
346
|
+
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
// ウィジェットでショートコードを使えるようにする
|
314
|
-
|
315
|
-
add_filter( 'widget_text', 'do_shortcode' );
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
// 任意のPHPファイルをショートコード化して扱えるようにする
|
320
|
-
|
321
|
-
function php_shortcode( $params = array() ) {
|
322
|
-
|
323
|
-
extract( shortcode_atts( array(
|
324
|
-
|
325
|
-
'file' => 'default'
|
326
|
-
|
327
|
-
), $params ));
|
328
|
-
|
329
|
-
ob_start();
|
330
|
-
|
331
|
-
include( get_template_directory() . "/$file.php" );
|
332
|
-
|
333
|
-
|
347
|
+
$the_query->the_post();
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
add_shortcode( 'my_php', 'php_shortcode' );
|
338
|
-
|
339
|
-
|
340
348
|
|
341
349
|
?>
|
342
350
|
|
343
|
-
```
|
344
|
-
|
345
|
-
re
|
351
|
+
<p><a href="http://投稿一覧のURL" ><?php the_title();?></a></p>
|
346
|
-
|
347
|
-
|
352
|
+
|
348
|
-
|
349
|
-
<?php
|
353
|
+
<?php
|
354
|
+
|
350
|
-
|
355
|
+
endwhile;
|
356
|
+
|
357
|
+
endif;
|
358
|
+
|
351
|
-
|
359
|
+
wp_reset_query();
|
352
|
-
|
353
|
-
'post_type' => 'post', //ポストタイプ
|
354
|
-
|
355
|
-
'posts_per_page' => 5, //表示件数
|
356
|
-
|
357
|
-
);
|
358
|
-
|
359
|
-
$the_query = new WP_Query( $args );
|
360
|
-
|
361
|
-
if ( $the_query->have_posts() ):
|
362
|
-
|
363
|
-
while ( $the_query->have_posts() ):
|
364
|
-
|
365
|
-
$the_query->the_post();
|
366
360
|
|
367
361
|
?>
|
368
362
|
|
369
|
-
<p><a href="http://投稿一覧のURL" ><?php the_title();?></a></p>
|
370
|
-
|
371
|
-
<?php
|
372
|
-
|
373
|
-
endwhile;
|
374
|
-
|
375
|
-
endif;
|
376
|
-
|
377
|
-
wp_reset_query();
|
378
|
-
|
379
|
-
?>
|
380
|
-
|
381
363
|
```
|
382
364
|
|
383
365
|
カスタムHTMLのウィジェットを追加して以下を書き込む
|
3
修正依頼があったため
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ワードプレスでわからないことがあります。
|
test
CHANGED
@@ -244,125 +244,7 @@
|
|
244
244
|
|
245
245
|
```
|
246
246
|
|
247
|
-
|
247
|
+
|
248
|
-
|
249
|
-
```php
|
250
|
-
|
251
|
-
<!DOCTYPE html>
|
252
|
-
|
253
|
-
<html lang="ja">
|
254
|
-
|
255
|
-
<head>
|
256
|
-
|
257
|
-
<meta charset="UTF-8">
|
258
|
-
|
259
|
-
<title><?php wp_title('|', true, 'right'); bloginfo('name'); ?></title>
|
260
|
-
|
261
|
-
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
|
262
|
-
|
263
|
-
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>">
|
264
|
-
|
265
|
-
<?php wp_head(); ?>
|
266
|
-
|
267
|
-
</head>
|
268
|
-
|
269
|
-
<body>
|
270
|
-
|
271
|
-
<?php if(is_front_page()) { if (get_header_image() !='') { ?>
|
272
|
-
|
273
|
-
<div id="main_image">
|
274
|
-
|
275
|
-
<img src="<?php header_image(); ?>" alt="" title="" />
|
276
|
-
|
277
|
-
</div>
|
278
|
-
|
279
|
-
<?php }; }; ?>
|
280
|
-
|
281
|
-
<div id="header" class="container">
|
282
|
-
|
283
|
-
<h1><a href="<?php echo home_url('/'); ?>"><?php bloginfo('name');?></a></h1>
|
284
|
-
|
285
|
-
<div class="wrapper"><?php wp_nav_menu(); ?></div>
|
286
|
-
|
287
|
-
</div><!--/header-->
|
288
|
-
|
289
|
-
```
|
290
|
-
|
291
|
-
page.php
|
292
|
-
|
293
|
-
```php
|
294
|
-
|
295
|
-
<?php get_header(); ?>
|
296
|
-
|
297
|
-
<div id="main" class="container">
|
298
|
-
|
299
|
-
<div id="posts">
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
<?php if(have_posts()):
|
304
|
-
|
305
|
-
while(have_posts()):
|
306
|
-
|
307
|
-
the_post();
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
?>
|
312
|
-
|
313
|
-
<div class="post">
|
314
|
-
|
315
|
-
<div class="post-header">
|
316
|
-
|
317
|
-
<h2>
|
318
|
-
|
319
|
-
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
320
|
-
|
321
|
-
</h2>
|
322
|
-
|
323
|
-
</div>
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
<div class="post-content">
|
328
|
-
|
329
|
-
<?php the_content(); ?>
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
</div>
|
334
|
-
|
335
|
-
</div>
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
<?php endwhile;
|
340
|
-
|
341
|
-
else:
|
342
|
-
|
343
|
-
?>
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
<p>ページはありません!</p>
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
<?php endif;
|
352
|
-
|
353
|
-
?>
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
</div><!--/posts-->
|
358
|
-
|
359
|
-
<?php get_sidebar(); ?>
|
360
|
-
|
361
|
-
</div><!--/main -->
|
362
|
-
|
363
|
-
<?php get_footer(); ?>
|
364
|
-
|
365
|
-
```
|
366
248
|
|
367
249
|
footer.php
|
368
250
|
|
@@ -498,20 +380,74 @@
|
|
498
380
|
|
499
381
|
```
|
500
382
|
|
501
|
-
|
502
|
-
|
503
|
-
編集しなおしました。
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
追記です。
|
508
|
-
|
509
|
-
サイドバーにあるワードプレスに最初からついているカスタムHTMLのウィジェットです。
|
510
|
-
|
511
|
-
ショートコードも書き漏れがありました。
|
512
|
-
|
513
|
-
|
514
|
-
|
515
383
|
カスタムHTMLのウィジェットを追加して以下を書き込む
|
516
384
|
|
517
385
|
[my_php file="recent_posts"]
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
ワードプレスのjavascriptのプラグイン
|
390
|
+
|
391
|
+
```javascript
|
392
|
+
|
393
|
+
jQuery(function() {
|
394
|
+
|
395
|
+
jQuery(".menu li").hover(function() {
|
396
|
+
|
397
|
+
jQuery(this).children('ul').show();
|
398
|
+
|
399
|
+
}, function() {
|
400
|
+
|
401
|
+
jQuery(this).children('ul').hide();
|
402
|
+
|
403
|
+
});//プルダウンメニューが表示されます
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
var page;
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
jQuery('.more a').on('click', function(event) {
|
412
|
+
|
413
|
+
//aリンクの動作を停止
|
414
|
+
|
415
|
+
event.preventDefault();
|
416
|
+
|
417
|
+
//リンク先URLを取得
|
418
|
+
|
419
|
+
page = jQuery(this).attr('href');
|
420
|
+
|
421
|
+
jQuery(this).parent().load(page+' div.post-content p',function(){
|
422
|
+
|
423
|
+
jQuery(this).parent().children().eq(0).hide();
|
424
|
+
|
425
|
+
});
|
426
|
+
|
427
|
+
//続きを読む ajaxでページ遷移せずにsingle.phpの一部が表示される
|
428
|
+
|
429
|
+
});
|
430
|
+
|
431
|
+
jQuery('a[href^=#]').click(function(){
|
432
|
+
|
433
|
+
var speed = 500;
|
434
|
+
|
435
|
+
var href= jQuery(this).attr("href");
|
436
|
+
|
437
|
+
var target = jQuery(href == "#" || href == "" ? 'html' : href);
|
438
|
+
|
439
|
+
var position = target.offset().top;
|
440
|
+
|
441
|
+
jQuery("html, body").animate({scrollTop:position}, speed, "swing");
|
442
|
+
|
443
|
+
return false;
|
444
|
+
|
445
|
+
});//ページ内リンクすることができる
|
446
|
+
|
447
|
+
});
|
448
|
+
|
449
|
+
```
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
関係のないテンプレートの表記を削除しました。
|
2
修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -501,3 +501,17 @@
|
|
501
501
|
|
502
502
|
|
503
503
|
編集しなおしました。
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
追記です。
|
508
|
+
|
509
|
+
サイドバーにあるワードプレスに最初からついているカスタムHTMLのウィジェットです。
|
510
|
+
|
511
|
+
ショートコードも書き漏れがありました。
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
カスタムHTMLのウィジェットを追加して以下を書き込む
|
516
|
+
|
517
|
+
[my_php file="recent_posts"]
|
1
わかりやすく編集しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,460 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
|
10
|
+
|
11
|
+
ウィジェットについて、すごくご丁寧に教えていただいたのですが、"http://投稿一覧のURL"の部分で、記事一覧の投稿が表示されるページが複数あったときに、その記事の載っている記事一覧のページにページ遷移させたいのですが、やりかたが分かりませんので教えてください。調べ方が下手でなかなかそのやり方が書いてあるサイトにたどり着けなく、6時間はまっています。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
index.php
|
16
|
+
|
17
|
+
```php
|
18
|
+
|
19
|
+
<?php get_header(); ?>
|
20
|
+
|
21
|
+
<div id="main" class="container">
|
22
|
+
|
23
|
+
<div id="posts">
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
<?php if(have_posts()):
|
28
|
+
|
29
|
+
while(have_posts()):
|
30
|
+
|
31
|
+
the_post();
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
?>
|
36
|
+
|
37
|
+
<?php $p_slug = get_page_uri(get_the_ID()); ?>
|
38
|
+
|
39
|
+
<div id="<?php echo $p_slug ?>"></div>
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
<div id="test"></div>
|
44
|
+
|
45
|
+
<div class="post">
|
46
|
+
|
47
|
+
<div class="post-header">
|
48
|
+
|
49
|
+
<h2>
|
50
|
+
|
51
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
52
|
+
|
53
|
+
</h2>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div class="post-meta">
|
58
|
+
|
59
|
+
<?php echo get_the_date(); ?> 【<?php the_category(', ') ?>】
|
60
|
+
|
61
|
+
</div>
|
62
|
+
|
63
|
+
<div class="post-content">
|
64
|
+
|
65
|
+
<div class="post-image">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<?php if(has_post_thumbnail()): ?>
|
70
|
+
|
71
|
+
<?php the_post_thumbnail(array(100, 100)); ?>
|
72
|
+
|
73
|
+
<?php else: ?>
|
74
|
+
|
75
|
+
<img src="<?php echo get_template_directory_uri(); ?>/images.jpg" width="100" height="100">
|
76
|
+
|
77
|
+
<?php endif; ?>
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
</div>
|
82
|
+
|
83
|
+
<div class="post-body">
|
84
|
+
|
85
|
+
<div class="post-body-excerpt">
|
86
|
+
|
87
|
+
<?php the_content('',false,''); ?>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
<div class="more"><a href="<?php the_permalink(); ?>">続きを読む</a></div>
|
94
|
+
|
95
|
+
<a href="<?php echo '#'.$p_slug ?>">ここ</a>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
</div>
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
<?php endwhile;
|
106
|
+
|
107
|
+
else:
|
108
|
+
|
109
|
+
?>
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
<p>記事はありません!</p>
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
<?php endif;
|
118
|
+
|
119
|
+
?>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<div class="navigation">
|
124
|
+
|
125
|
+
<div class="prev"><?php previous_posts_link(); ?></div>
|
126
|
+
|
127
|
+
<div class="next"><?php next_posts_link(); ?></div>
|
128
|
+
|
129
|
+
</div>
|
130
|
+
|
131
|
+
</div><!--/posts-->
|
132
|
+
|
133
|
+
<?php get_sidebar(); ?>
|
134
|
+
|
135
|
+
</div><!--/main -->
|
136
|
+
|
137
|
+
<?php get_footer(); ?>
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
single.php
|
142
|
+
|
143
|
+
```php
|
144
|
+
|
145
|
+
<?php get_header(); ?>
|
146
|
+
|
147
|
+
<div id="main" class="container">
|
148
|
+
|
149
|
+
<div id="posts">
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
<?php if(have_posts()):
|
154
|
+
|
155
|
+
while(have_posts()):
|
156
|
+
|
157
|
+
the_post();
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
?>
|
162
|
+
|
163
|
+
<div class="post">
|
164
|
+
|
165
|
+
<div class="post-header">
|
166
|
+
|
167
|
+
<h2>
|
168
|
+
|
169
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
170
|
+
|
171
|
+
</h2>
|
172
|
+
|
173
|
+
</div>
|
174
|
+
|
175
|
+
<div class="post-meta">
|
176
|
+
|
177
|
+
<?php echo get_the_date(); ?> 【<?php the_category(', ') ?>】
|
178
|
+
|
179
|
+
</div>
|
180
|
+
|
181
|
+
<div class="post-content">
|
182
|
+
|
183
|
+
<p>
|
184
|
+
|
185
|
+
<?php the_content(); ?>
|
186
|
+
|
187
|
+
</p>
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
</div>
|
192
|
+
|
193
|
+
</div>
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
<div class="navigation">
|
198
|
+
|
199
|
+
<div class="prev"><?php previous_post_link(); ?></div>
|
200
|
+
|
201
|
+
<div class="next"><?php next_post_link(); ?></div>
|
202
|
+
|
203
|
+
</div>
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
<?php endwhile;
|
208
|
+
|
209
|
+
else:
|
210
|
+
|
211
|
+
?>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<p>記事はありません!</p>
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<?php endif;
|
220
|
+
|
221
|
+
?>
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
</div><!--/posts-->
|
226
|
+
|
227
|
+
<?php get_sidebar(); ?>
|
228
|
+
|
229
|
+
</div><!--/main -->
|
230
|
+
|
231
|
+
<?php get_footer(); ?>
|
232
|
+
|
233
|
+
```
|
234
|
+
|
235
|
+
sidebar.php
|
236
|
+
|
237
|
+
```php
|
238
|
+
|
239
|
+
<div id="sidebar">
|
240
|
+
|
241
|
+
<?php dynamic_sidebar(); ?>
|
242
|
+
|
243
|
+
</div><!--/sidebar-->
|
244
|
+
|
245
|
+
```
|
246
|
+
|
247
|
+
header.php
|
248
|
+
|
249
|
+
```php
|
250
|
+
|
251
|
+
<!DOCTYPE html>
|
252
|
+
|
253
|
+
<html lang="ja">
|
254
|
+
|
255
|
+
<head>
|
256
|
+
|
257
|
+
<meta charset="UTF-8">
|
258
|
+
|
259
|
+
<title><?php wp_title('|', true, 'right'); bloginfo('name'); ?></title>
|
260
|
+
|
261
|
+
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
|
262
|
+
|
263
|
+
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>">
|
264
|
+
|
265
|
+
<?php wp_head(); ?>
|
266
|
+
|
267
|
+
</head>
|
268
|
+
|
269
|
+
<body>
|
270
|
+
|
271
|
+
<?php if(is_front_page()) { if (get_header_image() !='') { ?>
|
272
|
+
|
273
|
+
<div id="main_image">
|
274
|
+
|
275
|
+
<img src="<?php header_image(); ?>" alt="" title="" />
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
<?php }; }; ?>
|
280
|
+
|
281
|
+
<div id="header" class="container">
|
282
|
+
|
283
|
+
<h1><a href="<?php echo home_url('/'); ?>"><?php bloginfo('name');?></a></h1>
|
284
|
+
|
285
|
+
<div class="wrapper"><?php wp_nav_menu(); ?></div>
|
286
|
+
|
287
|
+
</div><!--/header-->
|
288
|
+
|
289
|
+
```
|
290
|
+
|
291
|
+
page.php
|
292
|
+
|
293
|
+
```php
|
294
|
+
|
295
|
+
<?php get_header(); ?>
|
296
|
+
|
297
|
+
<div id="main" class="container">
|
298
|
+
|
299
|
+
<div id="posts">
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<?php if(have_posts()):
|
304
|
+
|
305
|
+
while(have_posts()):
|
306
|
+
|
307
|
+
the_post();
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
?>
|
312
|
+
|
313
|
+
<div class="post">
|
314
|
+
|
315
|
+
<div class="post-header">
|
316
|
+
|
317
|
+
<h2>
|
318
|
+
|
319
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
320
|
+
|
321
|
+
</h2>
|
322
|
+
|
323
|
+
</div>
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
<div class="post-content">
|
328
|
+
|
329
|
+
<?php the_content(); ?>
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
</div>
|
334
|
+
|
335
|
+
</div>
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
<?php endwhile;
|
340
|
+
|
341
|
+
else:
|
342
|
+
|
343
|
+
?>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<p>ページはありません!</p>
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
<?php endif;
|
352
|
+
|
353
|
+
?>
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
</div><!--/posts-->
|
358
|
+
|
359
|
+
<?php get_sidebar(); ?>
|
360
|
+
|
361
|
+
</div><!--/main -->
|
362
|
+
|
363
|
+
<?php get_footer(); ?>
|
364
|
+
|
365
|
+
```
|
366
|
+
|
367
|
+
footer.php
|
368
|
+
|
369
|
+
```php
|
370
|
+
|
371
|
+
<div id="footer" class="container">
|
372
|
+
|
373
|
+
Copyright 2017<?php if(date("Y")!=2017) echo date("-Y"); ?> All right reserved, gomatan1258
|
374
|
+
|
375
|
+
</div><!--/footer-->
|
376
|
+
|
377
|
+
<?php wp_footer(); ?>
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
</body>
|
382
|
+
|
383
|
+
</html>
|
384
|
+
|
385
|
+
```
|
386
|
+
|
387
|
+
function.php
|
388
|
+
|
389
|
+
```php
|
390
|
+
|
391
|
+
<?php
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
add_theme_support( 'custom-header' );
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
add_theme_support('menus');
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
register_sidebar(
|
404
|
+
|
405
|
+
array(
|
406
|
+
|
407
|
+
before_widget => '<div class="widget">',
|
408
|
+
|
409
|
+
after_widget => '</div>',
|
410
|
+
|
411
|
+
before_title => '<h3>',
|
412
|
+
|
413
|
+
after_title => '</h3>',
|
414
|
+
|
415
|
+
)
|
416
|
+
|
417
|
+
);
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
add_theme_support('post-thumbnails');
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
$cssdir = get_stylesheet_directory_uri();
|
426
|
+
|
427
|
+
wp_enqueue_script( 'theme-script', $cssdir.'/script.php', array('jquery'));
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
// ウィジェットでショートコードを使えるようにする
|
432
|
+
|
433
|
+
add_filter( 'widget_text', 'do_shortcode' );
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
// 任意のPHPファイルをショートコード化して扱えるようにする
|
438
|
+
|
439
|
+
function php_shortcode( $params = array() ) {
|
440
|
+
|
441
|
+
extract( shortcode_atts( array(
|
442
|
+
|
443
|
+
'file' => 'default'
|
444
|
+
|
445
|
+
), $params ));
|
446
|
+
|
447
|
+
ob_start();
|
448
|
+
|
449
|
+
include( get_template_directory() . "/$file.php" );
|
450
|
+
|
451
|
+
return ob_get_clean();
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
add_shortcode( 'my_php', 'php_shortcode' );
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
?>
|
460
|
+
|
461
|
+
```
|
462
|
+
|
9
463
|
recent_posts.php
|
10
464
|
|
11
465
|
```php
|
@@ -44,36 +498,6 @@
|
|
44
498
|
|
45
499
|
```
|
46
500
|
|
47
|
-
|
501
|
+
|
48
|
-
|
49
|
-
|
502
|
+
|
50
|
-
|
51
|
-
// ウィジェットでショートコードを使えるようにする
|
52
|
-
|
53
|
-
add_filter( 'widget_text', 'do_shortcode' );
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
// 任意のPHPファイルをショートコード化して扱えるようにする
|
58
|
-
|
59
|
-
function php_shortcode( $params = array() ) {
|
60
|
-
|
61
|
-
extract( shortcode_atts( array(
|
62
|
-
|
63
|
-
'file' => 'default'
|
64
|
-
|
65
|
-
), $params ));
|
66
|
-
|
67
|
-
|
503
|
+
編集しなおしました。
|
68
|
-
|
69
|
-
include( get_template_directory() . "/$file.php" );
|
70
|
-
|
71
|
-
return ob_get_clean();
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
add_shortcode( 'my_php', 'php_shortcode' );
|
76
|
-
|
77
|
-
```
|
78
|
-
|
79
|
-
ウィジェットについて、すごくご丁寧に教えていただいたのですが、"http://投稿一覧のURL"の部分で、記事一覧の投稿が表示されるページが複数あったときに、その記事の載っている記事一覧のページにページ遷移させたいのですが、やりかたが分かりませんので教えてください。調べ方が下手でなかなかそのやり方が書いてあるサイトにたどり着けなく、6時間はまっています。
|