質問編集履歴
1
質問内容の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,22 +1,66 @@
|
|
1
1
|
Wordpressでサイトを作っています。
|
2
|
-
固定ページに
|
2
|
+
固定ページに、カテゴリーの一覧を表示させたいと考えています。デフォルトの「投稿」にあるカテゴリーから、1種類(works)だけを表示させています。
|
3
|
+
サブクエリで取得しているせいか、ページネーションが上手く動作しません。
|
4
|
+
2ページ目を押しても、1ページ目と同じ内容になっています。スラッグは/page/2/と正常に動いています。
|
3
5
|
|
4
|
-
ページネーションは、下記コードです。
|
5
6
|
|
7
|
+
|
8
|
+
ページ全体のPHPと、ページネーションのコードを下記にまとめました。
|
9
|
+
|
6
10
|
```ここに言語を入力
|
11
|
+
<!-- カテゴリー(works) -->
|
7
|
-
<div class="
|
12
|
+
<div class="category1">
|
13
|
+
<h2 class="title">制作実績</h2>
|
14
|
+
<ul class="category-list">
|
15
|
+
<?php
|
16
|
+
$args = array(
|
17
|
+
'category_name' => 'works',
|
18
|
+
'posts_per_page' =>3
|
19
|
+
);
|
20
|
+
$the_query = new WP_Query($args);
|
21
|
+
if($the_query->have_posts()):
|
22
|
+
?>
|
23
|
+
<?php while($the_query->have_posts()): $the_query->the_post(); ?>
|
24
|
+
<li class="contents contents1">
|
25
|
+
<a href="<?php the_permalink(); ?>" class="link">
|
26
|
+
<?php the_post_thumbnail(); ?>
|
27
|
+
<p <?php post_class('category type'); ?>><?php the_field('works'); ?></p>
|
28
|
+
<?php the_content(); ?>
|
29
|
+
</a>
|
30
|
+
</li>
|
31
|
+
<? endwhile ?>
|
32
|
+
<?php wp_reset_postdata(); ?>
|
33
|
+
<?php endif ?>
|
34
|
+
</ul>
|
35
|
+
</div>
|
8
36
|
|
37
|
+
<!-- 下記からページネーションのコードです(公式参照) -->
|
38
|
+
<?php
|
39
|
+
//Protect against arbitrary paged values
|
9
|
-
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
|
40
|
+
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
|
41
|
+
|
10
|
-
$
|
42
|
+
$args = array(
|
43
|
+
'posts_per_page' => 3,
|
44
|
+
'category_name' => 'works',
|
11
|
-
|
45
|
+
'paged' => $paged,
|
12
|
-
'type' => 'list',
|
13
|
-
'paged' => get_query_var('paged', 1)
|
14
46
|
);
|
15
|
-
echo paginate_links($paging);
|
16
|
-
?></div>
|
17
47
|
|
48
|
+
$the_query = new WP_Query( $args );
|
49
|
+
?>
|
50
|
+
|
51
|
+
<?php
|
52
|
+
$big = 999999999; // need an unlikely integer
|
53
|
+
|
54
|
+
echo paginate_links( array(
|
55
|
+
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
|
56
|
+
'format' => '?paged=%#%',
|
57
|
+
'current' => max( 1, get_query_var('paged') ),
|
58
|
+
'total' => $the_query->max_num_pages
|
59
|
+
) );
|
60
|
+
?>
|
61
|
+
|
62
|
+
|
18
63
|
```
|
19
64
|
|
20
|
-
パーマリンク設定を「日付と投稿名」にした場合、1ページ目のパーマリンクは「http://localhost:81/blog/news/」で、2ページ目以降から、「http://localhost:81/blog/news/page/2/」と、記事はそのままでパーマリンクだけが変更しているようです。
|
21
|
-
|
22
|
-
|
65
|
+
検索しても分からなかったので、質問させていただきました。
|
66
|
+
宜しくお願いします。
|