teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

ファイル変更履歴追記

2018/01/22 02:52

投稿

Nerf.this
Nerf.this

スコア14

title CHANGED
File without changes
body CHANGED
@@ -23,7 +23,7 @@
23
23
  ###補足情報(言語/FW/ツール等のバージョンなど)
24
24
  WordPress 4.7.8
25
25
 
26
- ###追記
26
+ ###追記
27
27
  目標のURL(例:2ページ目)
28
28
  理想
29
29
  `http://example.com/記事スラッグ/x1/y1/?cpage=2`
@@ -66,4 +66,49 @@
66
66
  add_rewrite_rule('([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?name=$matches[1]&cpage=$matches[2]', 'top');
67
67
  add_rewrite_rule('[^/]+/([^/]+)/?cpage=([0-9]{1,})/?$ ', 'index.php?attachment=$matches[1]&cpage=$matches[2] ', 'top');
68
68
  };
69
+ ```
70
+
71
+ ###追記2
72
+ Debug Barで確認したページリクエスト
73
+ ローカル(MAMP)
74
+ ```
75
+ Request:
76
+ 記事スラッグ/x1/y1
77
+
78
+ Query String:
79
+ name=記事スラッグ&cpage=2&y=y2
80
+
81
+ Matched Rewrite Rule:
82
+ ([^/]+)/x1(/(.*))?/?$
83
+
84
+ Matched Rewrite Query:
85
+ name=記事スラッグ&y=y1
86
+ ```
87
+ サーバー(functions.phpに追加後)
88
+ ```
89
+ Request:
90
+ 記事スラッグ/x1/y1
91
+
92
+ Query String:
93
+ name=記事スラッグ&cpage=-2%2F&y=y2
94
+
95
+ Matched Rewrite Rule:
96
+ ([^/]+)/x1(/(.*))?/?$
97
+
98
+ Matched Rewrite Query:
99
+ name=記事スラッグ&y=y1
100
+ ```
101
+ サーバー(functions.phpに追加前)
102
+ ```
103
+ Request:
104
+ 記事スラッグ/x1/y1/comment-page-2
105
+
106
+ Query String:
107
+ name=記事スラッグ&y=y1%2Fcomment-page-2
108
+
109
+ Matched Rewrite Rule:
110
+ ([^/]+)/x1(/(.*))?/?$
111
+
112
+ Matched Rewrite Query:
113
+ name=記事スラッグ&y=y1%2Fcomment-page-2
69
114
  ```

2

誤字の修正

2018/01/22 02:52

投稿

Nerf.this
Nerf.this

スコア14

title CHANGED
File without changes
body CHANGED
@@ -16,7 +16,7 @@
16
16
  add_rewrite_endpoint('x3', EP_PERMALINK, 'y3');
17
17
  }
18
18
  ```
19
- 実際に叩くURLは`http://example.com/x1/y1/?cpage=xxx`になるのですが、`cpage=1`の場合は期待通りコメントの1ページ目が表示されるのですが、2より大きい数値を指定するとWordPressのデフォルトのリライトルールにより`http://example.com/x1/y1/comment-page-2/`になってしまいます。
19
+ 実際に叩くURLは`http://example.com/記事スラッグ/x1/y1/?cpage=xxx`になるのですが、`cpage=1`の場合は期待通りコメントの1ページ目が表示されるのですが、2より大きい数値を指定するとWordPressのデフォルトのリライトルールにより`http://example.com/記事スラッグ/x1/y1/comment-page-2/`になってしまいます。
20
20
 
21
21
  自分で追加したリライトルールに則ってページングしたいため、`cpage`を残したままにしたいです。
22
22
 
@@ -26,11 +26,11 @@
26
26
  ###追記
27
27
  目標のURL(例:2ページ目)
28
28
  理想
29
- `http://example.com/x1/y1/?cpage=2`
29
+ `http://example.com/記事スラッグ/x1/y1/?cpage=2`
30
30
  現状
31
- `http://example.com/x1/y1/comment-page-2/`
31
+ `http://example.com/記事スラッグ/x1/y1/comment-page-2/`
32
32
  下記my_add_single_rewrite2()追記後
33
- `http://example.com/x1/y1/?cpage=-2%2F`
33
+ `http://example.com/記事スラッグ/x1/y1/?cpage=-2%2F`
34
34
 
35
35
  *現状の設定について
36
36
  functions.php

1

質問にて求められたファイル内容の追記

2018/01/19 05:19

投稿

Nerf.this
Nerf.this

スコア14

title CHANGED
File without changes
body CHANGED
@@ -21,4 +21,49 @@
21
21
  自分で追加したリライトルールに則ってページングしたいため、`cpage`を残したままにしたいです。
22
22
 
23
23
  ###補足情報(言語/FW/ツール等のバージョンなど)
24
- WordPress 4.7.8
24
+ WordPress 4.7.8
25
+
26
+ ###追記
27
+ 目標のURL(例:2ページ目)
28
+ 理想
29
+ `http://example.com/x1/y1/?cpage=2`
30
+ 現状
31
+ `http://example.com/x1/y1/comment-page-2/`
32
+ 下記my_add_single_rewrite2()追記後
33
+ `http://example.com/x1/y1/?cpage=-2%2F`
34
+
35
+ *現状の設定について
36
+ functions.php
37
+ ```php
38
+ add_filter('init', 'my_add_single_rewrite1');
39
+ add_filter('init', 'my_add_single_rewrite2');
40
+ add_filter('init', 'my_add_single_rewrite3');
41
+
42
+ function my_add_single_rewrite1() {
43
+ add_rewrite_endpoint('x1', EP_PERMALINK, 'y1');
44
+ add_rewrite_endpoint('x2', EP_PERMALINK, 'y2');
45
+ add_rewrite_endpoint('x3', EP_PERMALINK, 'y3');
46
+ }
47
+
48
+ function my_add_single_rewrite2() {
49
+ global $wp_rewrite;
50
+ $wp_rewrite->comments_pagination_base = '?cpage=';
51
+ }
52
+
53
+ function my_add_single_rewrite3( $array ) {
54
+ add_rewrite_rule('smart-custom-fields/[^/]+/attachment/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
55
+ add_rewrite_rule('smart-custom-fields/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?smart-custom-fields=$matches[1]&cpage=$matches[2]', 'top');
56
+ add_rewrite_rule('smart-custom-fields/[^/]+/([^/]+)/?cpage=([0-9]{1,})/?$', ' index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
57
+ add_rewrite_rule('media/[^/]+/attachment/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
58
+ add_rewrite_rule('media/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?media=$matches[1]&cpage=$matches[2]', 'top');
59
+ add_rewrite_rule('media/[^/]+/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
60
+ add_rewrite_rule('feature/[^/]+/attachment/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
61
+ add_rewrite_rule('feature/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?feature=$matches[1]&cpage=$matches[2]', 'top');
62
+ add_rewrite_rule('feature/[^/]+/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
63
+ add_rewrite_rule('.?.+?/attachment/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
64
+ add_rewrite_rule('(.?.+?)/?cpage=([0-9]{1,})/?$', 'index.php?pagename=$matches[1]&cpage=$matches[2]', 'top');
65
+ add_rewrite_rule('[^/]+/attachment/([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'top');
66
+ add_rewrite_rule('([^/]+)/?cpage=([0-9]{1,})/?$', 'index.php?name=$matches[1]&cpage=$matches[2]', 'top');
67
+ add_rewrite_rule('[^/]+/([^/]+)/?cpage=([0-9]{1,})/?$ ', 'index.php?attachment=$matches[1]&cpage=$matches[2] ', 'top');
68
+ };
69
+ ```