回答編集履歴
1
記入ミス
test
CHANGED
@@ -1,187 +1 @@
|
|
1
|
-
### ターム別一覧記事の作成(自分用)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
■■プラグイン「Custom Post Type Permalinks」を使用した方法
|
8
|
-
|
9
|
-
プラグイン有効化→「カスタマイズされたカスタムタクソノミーのパーマリンクを使用する。」にチェック。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
### functions.php
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
```php
|
18
|
-
|
19
|
-
<?php
|
20
|
-
|
21
|
-
/* カスタム投稿タイプを設定 */
|
22
|
-
|
23
|
-
function my_custom_post_topics() {
|
24
|
-
|
25
|
-
$labels = array(
|
26
|
-
|
27
|
-
'name' => _x('トピックス', 'post type general name'),
|
28
|
-
|
29
|
-
'singular_name' => _x('トピックス', 'post type singular name'),
|
30
|
-
|
31
|
-
'add_new' => _x('トピックスを追加', 'topics'),
|
32
|
-
|
33
|
-
'add_new_item' => __('トピックスを追加'),
|
34
|
-
|
35
|
-
'edit_item' => __('トピックスを編集'),
|
36
|
-
|
37
|
-
'new_item' => __('トピックス'),
|
38
|
-
|
39
|
-
'view_item' => __('トピックスを表示'),
|
40
|
-
|
41
|
-
'search_items' => __('トピックスを探す'),
|
42
|
-
|
43
|
-
'not_found' => __('トピックスはありません'),
|
44
|
-
|
45
|
-
'not_found_in_trash' => __('ゴミ箱にトピックスはありません'),
|
46
|
-
|
47
|
-
'parent_item_colon' => ''
|
48
|
-
|
49
|
-
);
|
50
|
-
|
51
|
-
$args = array(
|
52
|
-
|
53
|
-
'labels' => $labels,
|
54
|
-
|
55
|
-
'public' => true,
|
56
|
-
|
57
|
-
'publicly_queryable' => true,
|
58
|
-
|
59
|
-
'show_ui' => true,
|
60
|
-
|
61
|
-
'query_var' => true,
|
62
|
-
|
63
|
-
'rewrite' => true,
|
64
|
-
|
65
|
-
'capability_type' => 'post',
|
66
|
-
|
67
|
-
'hierarchical' => false,
|
68
|
-
|
69
|
-
'menu_position' => 5,
|
70
|
-
|
71
|
-
'has_archive' => true,
|
72
|
-
|
73
|
-
//'rewrite' => array( 'slug' => 'topics'),//変更前
|
74
|
-
|
75
|
-
'supports' => array('title','editor','author','thumbnail','revisions', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'page-attributes')
|
76
|
-
|
77
|
-
);
|
78
|
-
|
79
|
-
|
1
|
+
--記入ミス--------------------------------------
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
$args = array(
|
84
|
-
|
85
|
-
'label' => 'トピックスカテゴリー', /* ダッシュボードに表示する名前 */
|
86
|
-
|
87
|
-
'labels' => array(
|
88
|
-
|
89
|
-
'all_items' => 'トピックスカテゴリー一覧',
|
90
|
-
|
91
|
-
'add_new_item' => 'トピックスカテゴリーを追加'
|
92
|
-
|
93
|
-
),
|
94
|
-
|
95
|
-
'hierarchical' => true, /* カテゴリーの場合はtrue */
|
96
|
-
|
97
|
-
'show_ui' => true,
|
98
|
-
|
99
|
-
'show_in_nav_menus' => true,
|
100
|
-
|
101
|
-
'query_var' => true,
|
102
|
-
|
103
|
-
'rewrite' => true, /* パーマリンクのリライトの許可。 追記*/
|
104
|
-
|
105
|
-
'singular_label' => 'トピックスカテゴリー',
|
106
|
-
|
107
|
-
/*'rewrite' => array(
|
108
|
-
|
109
|
-
'slug' => 'topics',//★URLでtopics_catと表記されるのをtopicsに変更
|
110
|
-
|
111
|
-
'hierarchical' => true //★true にすると階層化したURLを使用可能にする
|
112
|
-
|
113
|
-
)*/ //変更前
|
114
|
-
|
115
|
-
);
|
116
|
-
|
117
|
-
register_taxonomy(
|
118
|
-
|
119
|
-
'topics_cat', /* 分類名 */
|
120
|
-
|
121
|
-
'topics', /* このタクソノミーを使う投稿タイプ */
|
122
|
-
|
123
|
-
$args
|
124
|
-
|
125
|
-
);
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
add_action('init', 'my_custom_post_topics');
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
//以下 追記
|
134
|
-
|
135
|
-
function rewrite_topics_category() {
|
136
|
-
|
137
|
-
$args = get_taxonomy( 'topics_cat' );
|
138
|
-
|
139
|
-
$args->show_admin_column = true;
|
140
|
-
|
141
|
-
$args->rewrite['slug'] = 'topics';
|
142
|
-
|
143
|
-
$args->rewrite['with_front'] = false;
|
144
|
-
|
145
|
-
register_taxonomy( 'topics_cat', 'topics', (array) $args );
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
add_action( 'init', 'rewrite_topics_category', 11 );
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
// カスタム投稿とカスタムタクソノミーを同一スラッグ(news)にした際に、ページネーションででる404エラーの回避。 変更前
|
156
|
-
|
157
|
-
//add_rewrite_rule('topics/([^/]+)/page/([0-9]+)/?$', 'index.php?topics_cat=$matches[1]&paged=$matches[2]', 'top');
|
158
|
-
|
159
|
-
?>
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
```
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
### その他必要なテンプレ
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
・
|
176
|
-
|
177
|
-
**archive-(カスタム投稿タイプ).php** ...記事一覧ページ
|
178
|
-
|
179
|
-
・
|
180
|
-
|
181
|
-
**taxonomy-(カスタムタクソノミー)-(ターム名).php** ...ターム別一覧ページ
|
182
|
-
|
183
|
-
・
|
184
|
-
|
185
|
-
**single-(カスタム投稿タイプ).php** ...投稿ページ
|
186
|
-
|
187
|
-
・
|