回答編集履歴
1
全面修正
test
CHANGED
@@ -1,5 +1,85 @@
|
|
1
|
-
|
1
|
+
見落としていたのですが、get_posts をお使いなんですね。
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
get_posts は、WP_Post オブジェクト(コンテンツのみ)を返すので、ページ情報が取れないですね。 ( [ クラスリファレンス/WP_Post ]( https://wpdocs.osdn.jp/%E3%82%AF%E3%83%A9%E3%82%B9%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Post ) 参照。 )
|
6
|
+
|
7
|
+
WP_Query オブジェクトを返す WP_Query() を使ってください。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
プログラム的には、 get_posts() 部分を WP_Query() を使うように書き換えて、next_posts_link の第2パラメータに WP_Query の `max_num_pages` を与えるようにしてください。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
[関数リファレンス/WP_Query](https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Query)
|
16
|
+
|
17
|
+
[テンプレートタグ/next_posts_link#WP_Query でループさせたとき](https://wpdocs.osdn.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/next_posts_link#WP_Query_.E3.81.A7.E3.83.AB.E3.83.BC.E3.83.97.E3.81.95.E3.81.9B.E3.81.9F.E3.81.A8.E3.81.8D)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
元々のテンプレートのget_post() より後をとりあえずこんな感じでしょうか:
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
$myposts = new WP_Query( $args );
|
30
|
+
|
31
|
+
if ( $myposts->have_posts() ):
|
32
|
+
|
33
|
+
while( $myposts->have_posts() ):
|
34
|
+
|
35
|
+
$myposts->the_post(); ?>
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
<div class="container">
|
40
|
+
|
41
|
+
(変更ないので省略)
|
42
|
+
|
43
|
+
</div>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
<?php endwhile; ?>
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
<div class="pagenav">
|
52
|
+
|
53
|
+
<span class="old">
|
54
|
+
|
55
|
+
<?php next_posts_link( '<i class="fa fa-chevron-circle-left"></i>古い記事', $myposts->max_num_pages );?>
|
56
|
+
|
57
|
+
</span>
|
58
|
+
|
59
|
+
<span class="new">
|
60
|
+
|
61
|
+
<?php previous_posts_link( '新しい記事<i class="fa fa-chevron-circle-right"></i>' );?>
|
62
|
+
|
63
|
+
</span>
|
64
|
+
|
65
|
+
</div>
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<?php wp_reset_postdata();
|
70
|
+
|
71
|
+
endif; ?>
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
</div>
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<!--/#main -->
|
82
|
+
|
83
|
+
(以下省略)
|
84
|
+
|
85
|
+
```
|