回答編集履歴
1
ソースの修正
answer
CHANGED
@@ -13,14 +13,34 @@
|
|
13
13
|
//function.php
|
14
14
|
//コメントページのスラッグを変更
|
15
15
|
add_action('init', function(){
|
16
|
-
|
16
|
+
global $wp_rewrite;
|
17
|
-
|
17
|
+
$wp_rewrite->comments_pagination_base = 'comments';
|
18
|
-
add_rewrite_rule('(.?.+?)/comments/([0-9]{1,})/?$', 'index.php?pagename=$matches[1]&cpage=$matches[2]', 'top');
|
19
18
|
});
|
20
19
|
|
20
|
+
add_filter('rewrite_rules_array',function ($rules){
|
21
|
+
$newrules = array();
|
22
|
+
|
23
|
+
$newrules['(.?.+?)/comments/([0-9]{1,})/?$'] = 'index.php?pagename=$matches[1]&cpage=$matches[2]';
|
24
|
+
$newrules['(.?.+?)/comments/([0-9]{1,})/?$'] = 'index.php?pagename=$matches[1]&cpage=$matches[2]';
|
25
|
+
$newrules['game/[^/]+/attachment/([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?attachment=$matches[1]&cpage=$matches[2]';
|
26
|
+
$newrules['game/([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?game=$matches[1]&cpage=$matches[2]';
|
27
|
+
$newrules['game/[^/]+/([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?attachment=$matches[1]&cpage=$matches[2]';
|
28
|
+
$newrules['.*wp-(atom|rdf|rss|rss2|feed|commentsrss2).php$'] = 'index.php?feed=old';
|
29
|
+
$newrules['comments/feed/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?&feed=$matches[1]&withcomments=1';
|
30
|
+
$newrules['comments/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?&feed=$matches[1]&withcomments=1';
|
31
|
+
$newrules['comments/embed/?$'] = 'index.php?&embed=true';
|
32
|
+
$newrules['.?.+?/attachment/([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?attachment=$matches[1]&cpage=$matches[2]';
|
33
|
+
$newrules['(.?.+?)/comments/?([0-9]{1,})/?$'] = 'index.php?pagename=$matches[1]&cpage=$matches[2]';
|
34
|
+
$newrules['[^/]+/attachment/([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?attachment=$matches[1]&cpage=$matches[2]';
|
35
|
+
$newrules['([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?name=$matches[1]&cpage=$matches[2]';
|
36
|
+
$newrules['[^/]+/([^/]+)/comments/?([0-9]{1,})/?$'] = 'index.php?attachment=$matches[1]&cpage=$matches[2]';
|
37
|
+
|
38
|
+
return $newrules + $rules;
|
39
|
+
});
|
40
|
+
|
21
41
|
add_filter( 'get_comments_pagenum_link', function( $result ){
|
22
42
|
if (preg_match( '{(.?.+?)/comments-([0-9]{1,})/}', $result, $m)) {
|
23
|
-
$result = $m[1] . '/comments/' . $m[2];
|
43
|
+
$result = $m[1] . '/comments/' . $m[2].'/';
|
24
44
|
return $result;
|
25
45
|
}
|
26
46
|
return $result;
|
@@ -28,8 +48,10 @@
|
|
28
48
|
|
29
49
|
add_filter( 'user_trailingslashit', function( $string, $type_of_url ){
|
30
50
|
if ( $type_of_url === 'commentpaged' ) {
|
31
|
-
if (preg_match( '{comments/}', $string)) {
|
51
|
+
if (preg_match( '{(.?.+?)/comments-([0-9]{1,})/}', $string, $m)) {
|
52
|
+
$result = $m[1] . '/comments/' . $m[2].'/';
|
32
|
-
return $
|
53
|
+
return $result;
|
54
|
+
|
33
55
|
}else{
|
34
56
|
return '';
|
35
57
|
}
|