質問編集履歴
2
見出し追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
##教えていただきたいこと
|
2
|
+
|
1
3
|
WordPressのtag.phpでページネーションを実装したのですが、
|
2
4
|
|
3
5
|
URLに「/page/2/」がつくと404エラーとなってしまいます。
|
@@ -25,6 +27,8 @@
|
|
25
27
|
|
26
28
|
|
27
29
|
|
30
|
+
|
31
|
+
##tag.phpソースコード
|
28
32
|
|
29
33
|
```
|
30
34
|
|
1
ソースコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,3 +21,171 @@
|
|
21
21
|
404エラーを解決する方法があればご教授いただきたく
|
22
22
|
|
23
23
|
よろしくお願いいたします。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
<?php
|
32
|
+
|
33
|
+
/*
|
34
|
+
|
35
|
+
Template Name: タグ一覧テンプレート
|
36
|
+
|
37
|
+
*/
|
38
|
+
|
39
|
+
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
|
40
|
+
|
41
|
+
$tag = get_queried_object();
|
42
|
+
|
43
|
+
$slugName = $tag->slug;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
$arrayPostType = get_post_types(array('public' => true, '_builtin' => false));
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
$the_query = new WP_Query([
|
52
|
+
|
53
|
+
'post_type' => $arrayPostType,
|
54
|
+
|
55
|
+
'post_status' => 'publish',
|
56
|
+
|
57
|
+
'paged' => $paged,
|
58
|
+
|
59
|
+
'posts_per_page' => 10,
|
60
|
+
|
61
|
+
'tag' => $slugName,
|
62
|
+
|
63
|
+
'orderby' => 'date',
|
64
|
+
|
65
|
+
'order' => 'DESC',
|
66
|
+
|
67
|
+
'meta_query' => [
|
68
|
+
|
69
|
+
[
|
70
|
+
|
71
|
+
'key' => 'list_invisible',
|
72
|
+
|
73
|
+
'compare' => 'NOT EXISTS',
|
74
|
+
|
75
|
+
],
|
76
|
+
|
77
|
+
[
|
78
|
+
|
79
|
+
'key' => 'list_invisible',
|
80
|
+
|
81
|
+
'compare' => '!=',
|
82
|
+
|
83
|
+
'value' => '1',
|
84
|
+
|
85
|
+
],
|
86
|
+
|
87
|
+
'relation' => 'OR',
|
88
|
+
|
89
|
+
],
|
90
|
+
|
91
|
+
]);
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
?>
|
96
|
+
|
97
|
+
<?php get_header(); ?>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
<article class="article">
|
102
|
+
|
103
|
+
<div class="section">
|
104
|
+
|
105
|
+
<div class="inner">
|
106
|
+
|
107
|
+
<div class="section__body">
|
108
|
+
|
109
|
+
<?php if ($the_query->have_posts()) : ?>
|
110
|
+
|
111
|
+
<ul class="article-list">
|
112
|
+
|
113
|
+
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
|
114
|
+
|
115
|
+
<li class="article-list__item">
|
116
|
+
|
117
|
+
<div>
|
118
|
+
|
119
|
+
<a href="<?php the_permalink(); ?>">
|
120
|
+
|
121
|
+
<figure><img src="<?php echo esc_url(CFS()->get('eyecatch_image')); ?>" class="eye-catching-image"></figure>
|
122
|
+
|
123
|
+
<div>
|
124
|
+
|
125
|
+
<p class="date"><time datetime="<?php the_time('Y.m.d'); ?>"><?php the_time('Y.m.d'); ?></time></p>
|
126
|
+
|
127
|
+
<p class="article-title"><?php the_title(); ?></p>
|
128
|
+
|
129
|
+
</div>
|
130
|
+
|
131
|
+
</a>
|
132
|
+
|
133
|
+
</div>
|
134
|
+
|
135
|
+
</li>
|
136
|
+
|
137
|
+
<?php endwhile; ?>
|
138
|
+
|
139
|
+
</ul>
|
140
|
+
|
141
|
+
<?php endif;
|
142
|
+
|
143
|
+
wp_reset_postdata(); ?>
|
144
|
+
|
145
|
+
</div>
|
146
|
+
|
147
|
+
</div>
|
148
|
+
|
149
|
+
</div>
|
150
|
+
|
151
|
+
<?php if ($the_query->max_num_pages > 1) : ?>
|
152
|
+
|
153
|
+
<nav class="pagination">
|
154
|
+
|
155
|
+
<?php
|
156
|
+
|
157
|
+
echo paginate_links(array(
|
158
|
+
|
159
|
+
'base' => get_pagenum_link(1) . '%_%',
|
160
|
+
|
161
|
+
'format' => 'page/%#%/',
|
162
|
+
|
163
|
+
'current' => max(1, $paged),
|
164
|
+
|
165
|
+
'mid_size' => 1,
|
166
|
+
|
167
|
+
'total' => $the_query->max_num_pages,
|
168
|
+
|
169
|
+
'type' => 'list',
|
170
|
+
|
171
|
+
'prev_text' => '<',
|
172
|
+
|
173
|
+
'next_text' => '>'
|
174
|
+
|
175
|
+
));
|
176
|
+
|
177
|
+
?>
|
178
|
+
|
179
|
+
</nav>
|
180
|
+
|
181
|
+
<?php endif; ?>
|
182
|
+
|
183
|
+
</article>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
<?php get_footer(); ?>
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
```
|