回答編集履歴
2
回答を修正し、ソースコード記載
test
CHANGED
@@ -27,3 +27,165 @@
|
|
27
27
|
- PHP - wordpress カスタム投稿&カテゴリー毎の月次アーカイブの作り方(59475)|teratail
|
28
28
|
|
29
29
|
[https://teratail.com/questions/59475](https://teratail.com/questions/59475)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
###追記2
|
34
|
+
|
35
|
+
前にあげた回答がよくなかったので、書き直しました。
|
36
|
+
|
37
|
+
以下で試してみてください。
|
38
|
+
|
39
|
+
`?><pre><?php`から`?></pre><?php`の部分はデバッグ用なので最終的には削除してください。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
####taxonomy-specialtopics_cat.phpに記述
|
44
|
+
|
45
|
+
```PHP
|
46
|
+
|
47
|
+
<select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
|
48
|
+
|
49
|
+
<option value=""><?php echo attribute_escape(('年度別')); ?></option>
|
50
|
+
|
51
|
+
<?php wp_get_archives('type=yearly&post_type=specialtopics&format=option&show_post_count=1'); ?>
|
52
|
+
|
53
|
+
</select>
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
####functions.php
|
60
|
+
|
61
|
+
```PHP
|
62
|
+
|
63
|
+
function my_getarchives_where( $where, $args ){
|
64
|
+
|
65
|
+
$taxonomy = get_query_var('taxonomy');
|
66
|
+
|
67
|
+
$term = get_query_var('term');
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
?><pre><?php
|
72
|
+
|
73
|
+
var_dump($taxonomy);
|
74
|
+
|
75
|
+
var_dump($term);
|
76
|
+
|
77
|
+
?></pre><?php
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
if(!empty($taxonomy)){
|
82
|
+
|
83
|
+
$where = $where . " AND t.taxonomy = '" . $taxonomy . "'";
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
if(!empty($term)){
|
88
|
+
|
89
|
+
$where = $where . " AND terms.slug = '" . $term . "'";
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
?><pre><?php
|
96
|
+
|
97
|
+
var_dump($where);
|
98
|
+
|
99
|
+
?></pre><?php
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
return $where;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
add_filter( 'getarchives_where', 'my_getarchives_where', 10, 2 );
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
function my_getarchives_join($join, $args){
|
112
|
+
|
113
|
+
global $wpdb;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
$join = " LEFT JOIN $wpdb->term_relationships as r ON $wpdb->posts.ID = r.object_ID
|
118
|
+
|
119
|
+
LEFT JOIN $wpdb->term_taxonomy as t ON r.term_taxonomy_id = t.term_taxonomy_id
|
120
|
+
|
121
|
+
LEFT JOIN $wpdb->terms as terms ON t.term_id = terms.term_id";
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
?><pre><?php
|
126
|
+
|
127
|
+
var_dump($join);
|
128
|
+
|
129
|
+
?></pre><?php
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
return $join;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
add_filter('getarchives_join', 'my_getarchives_join', 10, 2);
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
function my_year_link($url, $year){
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
$taxonomy = get_query_var('taxonomy');
|
146
|
+
|
147
|
+
$term = get_query_var('term');
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
?><pre><?php
|
152
|
+
|
153
|
+
var_dump($taxonomy);
|
154
|
+
|
155
|
+
var_dump($term);
|
156
|
+
|
157
|
+
?></pre><?php
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
if( !empty($taxonomy) ) {
|
162
|
+
|
163
|
+
$url = add_query_arg( 'taxonomy', $taxonomy, $url);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
if( !empty($term) ) {
|
168
|
+
|
169
|
+
$url = add_query_arg( 'term', $term, $url);
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
?><pre><?php
|
176
|
+
|
177
|
+
var_dump($url);
|
178
|
+
|
179
|
+
?></pre><?php
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
return $url;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
add_filter('year_link', 'my_year_link', 10, 2);
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
|
1
類似質問へのURL追記
test
CHANGED
@@ -17,3 +17,13 @@
|
|
17
17
|
- テンプレートタグ/wp get archives - WordPress Codex 日本語版
|
18
18
|
|
19
19
|
[http://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/wp_get_archives](http://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/wp_get_archives)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
###追記
|
24
|
+
|
25
|
+
以前も似たような質問を見て、回答した気がするなあと探してみたらありました。
|
26
|
+
|
27
|
+
- PHP - wordpress カスタム投稿&カテゴリー毎の月次アーカイブの作り方(59475)|teratail
|
28
|
+
|
29
|
+
[https://teratail.com/questions/59475](https://teratail.com/questions/59475)
|